ComboBox ValueMember
-
I have a problem with Combo Boxes that I just can't fathom. I'm creating a database front end working in VB.net. The front end requires loads if lists such as UK Counties, Suppliers etc. To handle these I've created Class Objects to hold an ID as an Integer and a KnownAs name string . These Objects are stored in an ArrayList inside a second Class which provides methods to supply the appropriate data when asked - I've split the data descriptive Class from the data handling Class as I eventually will use remoting and will pass an ArrayList of my data Objects to my data handling Object. These lists are shared and either static as in the case of Counties or have a Time To Refresh as in the case of Suppliers and exist for the life of the Application. The records, say Customer details are stored in their own Classes with the County value being stored as an ID. The values are written to the Form fields manually - I've not used binding. In the case of the Combo Box I set the DataSource to my data handling Class, the DisplayMember to my KnownAs string and the ValueMember to my ID (both values are Methods in my Class). On applying my record to the Form I set the Combo Box SelectedValue to the appropriate record ID value. Here's my problem - If my lists are sorted by ID it all works as expected. If, however, I set the Combo Box to sort the DisplayMember it all goes pear shaped. I realise that a Combo Box stores the ValueMember as a string and sorting the DisplayMember scrambles the ValueMember order, but I find it hard to believe that something I've been doing in Access for years doesn't work here. Apart from these niggling problems I'm very much in favour of DotNet. Any ideas ? Steve Answered my own problem: Sort the data within the query and turn ComboBox sorting off. The ArrayList is zero based as is the ComboBox list so provide a GetIndex procedure that searches the ArrayList for the required ID and returns the corresponding Index (Incremented Count from zero). PS ValueMember is an Object and not a String as I've previously stated.