I have a DataView called FubarView, which was created by a call to our database. The columns are Label, Value, RawName & PhoneNumber. After creation of the DataView, I added a sort order to the DataView with…
this.FubarView.Sort = "RawName, Value"
I then (amongst other irrelevant stuff like setting DisplayMember, etc.) bound it to my WinForms ComboBox…
cmbDefault.DataSource = this.FubarView;
This worked perfectly, with the ComboBox, displaying sorted information as intended. HOWEVER, when at a later point I tried to look at FubarView using the SelectedIndex from my ComboBox…
phoneNumber = this.FubarView.Table.Rows[cmbDefault.SelectedIndex]["PhoneNumber"]
…it would return the wrong value, as if FubarView went and sorted itself by Value again! How do you fix this?
This is because you are sorting a view on the table, not the actual table. So if you access the Table trough DataView.Table you get your original data.
If you want to access the sorted rows you should access them trough the DataView.