c#


datagridview data to list, then binding listbox to list, doesnt work?


I cant realize what is wrong here so that listBox is empty, instead of having one list inside?(Probably very easy to solve but I cant get it on my own yet)
public List<Karta> ubaciUListu()
{
List<Karta> Lista1 = new List<Karta>();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
Karta k = new Karta(0,"","");
// k.Id =(int)row.Cells[0].Value;
k.Pojam =(string) row.Cells[1].Value;
k.Opis = (string)row.Cells[2].Value;
Lista1.Add(k);
}
return Lista1;
}
private void btnNovaF_Click(object sender, EventArgs e)
{
//ubaciUListu();
this.Hide();
Form2 f2 = new Form2();
f2.ShowDialog();
}
First I am creating List from data in dgv(see here data in dgv)
then I am trying to bind listBox to this List
public Form2()
{
InitializeComponent();
Form1 f1 = new Form1();
List<Karta> nova = f1.ubaciUListu();
if(nova.Count!=0)
{
lstBox.DataSource = nova;
}
}
hope this will be helpful enough to detect issue. Thank you !
When you create a new instance of the form1, existing list will be cleared,
Form1 f1 = new Form1();
List<Karta> nova = f1.ubaciUListu();
Better way is to pass it to the 2nd form when you open it,
Form2 f2 = new Form2(Lista1);
Your form2 should be,
List<Karta> nova = new List<Karta>();
public Form2(List<Karta> input)
{
nova = input;
}
}

Related Links

Search users and sort by most number of mutual friends in Redis?
Sorting strings in custom order
How to filter grid view with object data source and business class in asp.net
Why does null-propagation of Nullable<T> return T and not Nullable<T>?
Add drop down in excel using EPplus
How to invoke a method accepting linq expression arguments
What is the best way to store some data in VSTO addin?
Reducing image dimension increases the file size C#
How to sign out a user in ASP.NET Core Identity
WPF: How to access specific DataTable from a different window
How to improve the performance of Leetcode 4sum-ii challenge
Web API OData function with TimeSpan
Can System.Drawing be used in an Azure web site?
Crystal Report “A date range required here”
Insert new records using Linq
Inheritance and Generic Type Setting

Categories

HOME
excel-formula
macros
azure-active-directory
itunesconnect
service
locale
spotfire
crm
itext7
sdk
msbi
css-selectors
swap
hibernate-mapping
drush
mbed
logstash-configuration
game-engine
wallet
google-street-view
webgl-earth
include-path
functional-dependencies
pixels
windows-mobile
paper-trail-gem
loopback
keil
wercker
circle
machine-code
gitosis
geocomplete
repeat
word-wrap
var
vpython
emacs24
xamarin-test-cloud
multi-select
scrollmagic
nls
sharing
firebase-polymer
dimensionality-reduction
ldd
key-value-store
syslog4j
paypal-subscriptions
calc
wizard
fadein
commercetools
javapackager
jsoncpp
glog
log-analysis
stderr
system.diagnostics
jad
mathics
shunting-yard
crystal-reports-7
growl
im4java
nest-initiative
rpt
visual-c#-express-2010
sigma-grid-control
node-mongodb-native
imaplib
facebook-likebox
caroufredsel
extensibility
forward-declaration
android-library
stringstream
proj4
wordbreaker
nx
mmo
database-restore
antixsslibrary
wpml
esi
shapado
pdf-reader
django-admin-tools
nude.js
jqzoom
zend-validate
for-xml
versions
uccapi
mysql-pconnect
web-widget
dojox.gfx
data-formats
file-icons

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile