Question Choosing the right control

Reggie213

Member
Joined
May 24, 2012
Messages
12
Programming Experience
Beginner
Hey all,

So I am putting together a form that will allow a user to filter the results returned from SQL server based on a selection.

I have the data in a datagridview and that is all working fine.

I would like to put a number of controls at the top to allow the user to filter the results however they desire.

I know what fields they will be filtering on and which ones they want as a string search, multi selectable etc.

I am fine with working out the logic that rebuilds the SQL string that pulls the data...

What I am not sure about is which control is best for the multi selection.

Example filter field : Product Category(PCAT)
Requirement : Select none, a single or multiple categories to display from the data set

ListView, Listbox and checkedlistbox dont allow for a datasource to be bound directly but offesr the best interface for a user to select multiple records..
Combobox allows for datasource but isnt a suitable for multi selecting.

Is it better to use the listview etc and just loop through to add all the items?

Reg

Using .net 2.0 & visual studio 2010
 
The ListView doesn't support data-binding but the ListBox and CheckedListBox do. The ListBox inherits the same ListControl class as the ComboBox and that's where the data-binding support comes from, while the CheckedListBox inherits ListBox.
 
Thank you for that, what confused me was the lack of valuemember and datamember in the properties window of checkedlistbox and listbox!
 
That would be DisplayMember rather than DataMember, and they are both present for a ListBox. The CheckedListBox doesn't officially support data-binding, which is why those members are hidden at design time. It does inherit ListBox though, so the functionality is there. What you can't do is bind anything to the check boxes and you may also find a few quirks. For instance, I always recommend setting the DisplayMember and ValueMember before setting the DataSource for a ComboBox or ListBox, but I've found that it must be done the other way around for a CheckedListBox.
 
Back
Top