Question Row source from combo box

TimAndersonPhoenix

New member
Joined
Aug 30, 2008
Messages
2
Programming Experience
1-3
I have a combo box on the form which is bound to a dataset. I need to get the row number in the dataset that is being shown in the combo box. I need to pass that value to another routine as a parameter. Any ideas on how to obtain the value?

Thanks,
Tim Anderson
 
Er.. You don't (shouldn't)?

DataTable is a storage of rows, and it is not meant to be ordered, nor is particular significance intended to be attached to order. DataViews provide order, and are capable of reporting what position a row is in

If youre coding in this way and relying on rows to be in a particular order, youre building a fragile house of cards... If you can explain what the othre routine will do with the row number, then we can bette rhelp you write your app as it should be written, rather than advising you how to fix the problem with a possibly ineffective solution
 
Thanks for the reply.

I needed the index value of the item so I could use another value of the same record that was displayed in the combobox. I figured out that it was SelectedIndex that I needed. The order was not critical in this case.

Thanks
 
If your combo is bound and is showing e.g. COLUMN_ONE as its display member but you need to use the value of COLUMN_FOUR in our code, you should just ask the combo for its SelectedItem, or ask the BindingSource that the combo is bound through for its .Current property. In the case of the BS, you get a DataRowView back, which has a .Row property exposing the (typed) datarow in use, or you can ask the DataRowView for the value in un-typed fashion:


myBSTheComboIsBoundTo.Current("COLUMN_FOUR")


Beware the assertion that selected index = the row index; it is a very weak assertion and fails as soon as a filter or order is imposed by an interim view. The methods of asking the combo for the row (SelectedItem) or the BS for the current are far better/reliable in all cases
 
Back
Top