F
farseer
Hi,
I have a combobox who's data source i set to an array of objects (call
it MyObject). these objects have get properties: key, value, descr. i
set ValueMember to "key", DisplayMember to "descr", and datasource to
the array of MyObjects.
How can i set the selected value of that combobox based on the
ValueMember OR how can i find the index of an item in the combobox BY
ValueMember?
here's an example. in the example below, the first parameter is
returned by get property "key", the second by "value", the third by
"descr".
MyObject[] arr = new MyObject[]
{
new MyObject( 1111, 100, "myobj1" ),
new MyObject( 2222, 200, "myobj2" ),
new MyObject( 3333, 300, "myobj3" ),
};
cmbBox.DataSoruce = arr;
cmbBox.ValueMember = "key";
cmbBox.DisplayMember = "descr";
Now at this point i have a cmbBox that has shows in it's dropdown
"myobj1","myobj2","myobj3". Now, i'd like to set the selected item
based on the ValueMember. for instance, i read 2222 from a file, so
i'd like to use this value to set the cmbBox selected index to 2...but
to do this, i need to know how to find the index of items by
valuemember.
I have a combobox who's data source i set to an array of objects (call
it MyObject). these objects have get properties: key, value, descr. i
set ValueMember to "key", DisplayMember to "descr", and datasource to
the array of MyObjects.
How can i set the selected value of that combobox based on the
ValueMember OR how can i find the index of an item in the combobox BY
ValueMember?
here's an example. in the example below, the first parameter is
returned by get property "key", the second by "value", the third by
"descr".
MyObject[] arr = new MyObject[]
{
new MyObject( 1111, 100, "myobj1" ),
new MyObject( 2222, 200, "myobj2" ),
new MyObject( 3333, 300, "myobj3" ),
};
cmbBox.DataSoruce = arr;
cmbBox.ValueMember = "key";
cmbBox.DisplayMember = "descr";
Now at this point i have a cmbBox that has shows in it's dropdown
"myobj1","myobj2","myobj3". Now, i'd like to set the selected item
based on the ValueMember. for instance, i read 2222 from a file, so
i'd like to use this value to set the cmbBox selected index to 2...but
to do this, i need to know how to find the index of items by
valuemember.