I want to copy all the items in a listbox to items of a combobox on runtime so need help
A:
Can't you just set the combobox's datasource to the same one the Listbox is using?
Mitch Wheat
2009-04-29 00:17:50
When i do that it selects only first value it finds for combobox and rest are not included :s
Mobin
2009-04-29 00:19:44
even though i do that i need to get the values in that list box also and then merge some values of list boxes in that combobox thats the problem here
Mobin
2009-04-29 00:23:10
+1
A:
for (int i = 0; i < listBox1.Items.Count; i++)
{
comboBox1.Items.Add(listBox1.Items[i]);
}
EDIT:
If you are populating the list control via the 'DataSource' property remember to set the source listbox 'DisplayMember' and 'ValueMember' properties:
listBox1.DisplayMember = "DisplayMember";
listBox1.ValueMember = "ValueMember";
and also the target combobox properties to the same values:
comboBox1.DisplayMember = "DisplayValue";
comboBox1.ValueMember = "ValueMember";
When an object is added to the list the listbox checks the 'DisplayMember' property. If the value of 'DisplayMember' doesn't exist or has its value set to an empty string the ToString() method is called on the object contained in the list item to obtain the text to display in the list.
Phaedrus
2009-04-29 00:30:05
it gives u text as system.data.dataview....... stuff thats what i get every time i try it is the issue i am trying to resolve here
Mobin
2009-04-29 00:34:12