Navigating a Filtered Dataset with a listbox
Posted on 2004-11-29
Ive been searching for the proper way to accomplish this seemingly simple task for several weeks now. Heres it is... I have a dataset loaded and the fields are displayed in text boxes on the form. To navigate this information I have a listbox that lists one of the fields (in this case it is peoples Names). Clicking on someones name will change the info in all the textboxes to that persons information. Now i had this working by moving to the row of the dataset based on the row selected from the listbox. This works fine. However, now i want to filter the records displayed in the listbox based on another field. So for example I might want to only display males or only females in the listbox. I am currently filtering this information using the following line:
ListBox1.DataSource = Members_dataset1.Tables("Members").Select("Gender='Male'", "Name", DataViewRowState.CurrentRows)
This works fine and filters the names shown in the listbox. However, this makes my previous way of navigating using the listbox not function properly, what is happening is the dataset row and the listbox row is not matching up anymore. I am not sure if this is the best way to do this, I dont think accessing the database again using another sql command to get a whole new dataset is the right way. Is there a better way? Thanks!!!