?
Solved

Navigating a Filtered Dataset with a listbox

Posted on 2004-11-29
5
Medium Priority
?
327 Views
Last Modified: 2010-04-23
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!!!
0
Comment
Question by:mgouzie
2 Comments
 
LVL 9

Accepted Solution

by:
caball88 earned 1000 total points
ID: 12702822
have you tried using a dataview? for example:

dim dataview1 as dataview

dataview1 = Members_dataset1.Tables("Members").defaultview

dataview1.rowfilter = "<your row filter here>"

this way the row number does not change and you are basically binding to a dataview for the data.
0
 
LVL 19

Assisted Solution

by:arif_eqbal
arif_eqbal earned 1000 total points
ID: 12705448
Your ListBox was bound to the whole Members_dataset1
Now after you used the Select method the Listbox now got bound to only the filtered record, so naturally it is now out of sync with the base dataset Members_dataset1.

Now the first question is why do you want to filter i.e. use the Select method in case you wanto navigate to a particular record you can use Currency Manager and navigate.

However in case you want to search say 5 records out of the total 10 in the original Dataset and let the user navigate between the newly selected 5 records, and when he wants he can revert back to all the 10 records.
Now if this is what you want then as mentioned by caball88 you need dataviews.

have a method called Bindcontrols, now this method will bind all the control to a Dataview, initially this dataview will be created from all the data in the basic dataset

Then you can filter out the records using Select method and recreate this dataview.

When you want to revert back to all records again re-create the view from all records in the dataset.

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question