tuortoam

tuortoam

  • NA
  • 12
  • 0

Display vs Primary Key in a ListBox

Oct 6 2003 4:59 PM
I've come up with a creative solution to a problem I had, but I have to believe there is a better way. Here I go: Overview: Data is an XML file which I read in using ReadXML into a DataSet. For some of the GUI list boxes, I assign the datasource to a new datatable that has two columns - an "id" column that stores the Primary key for the record, and a display field, which is the way I want to present the data (for ex: display field = concatenation of firstName and lastName). I assign the displaymember to the displayfield. Problem: How do I get the primary key for future data lookups when the user clicks on the display string? My Creative Solution: When the user clicks on the listbox row, I follow these steps: 1) stop screen updates to the listbox 2) set the displayfield to the ID field in the datatable 3) get the text value of the listbox (it's now set to the primary key) 4) set the displayfield back to the displaystring 5) allow screen updates to the list box This works fine for regular windows apps, but in the compactframework, the call to stop screen updates is not allowed. So, on slow devices, you can see the contents of the listbox switch back and forth from the display field, to the primary key field, and back again. I have to believe there is an easier way.... Any takers? -Ant

Answers (4)