-
Custom Combo Box
Hello all,
I need Hinsights and also advices about what I'd like to do. I would like to have a custom combo boxes in which I insert instances of certain class I made. I want that combo box to show only items that has a certain value in a certain field in my class. Is there a way to do such a filter to a combo box or it's just showing everything in its list ? If it's possible to do that, I would like to know what to look for in the events and or methods I should work on to be able to change the behavior of the default "SHOWING" of items.
Thanks in Advance.
-
Re: Custom Combo Box
You can override the OnMeasureItem and OnDrawItem... or you can create a custom ComboBox with an internal private array that holds all of the data, and the public collection could be updated to hold the filtered items.
-
Re: Custom Combo Box
Sounds like a plan. Thank you
-
Re: Custom Combo Box
I expressed myself incorrectly... Here's the Behavior I would like my Combo Box to have..
I have a database with secondary data ( data that are parents to other data ). That parent table has a field called Activated and the value is true false.
Here's what I'd like to do. Whenever I load an old data, I would like to be able to show all entry but whenever the User wants to specify the value of this combo box, I would like to show only Activated Items in the dropdownlist. I wanna use a list because I don't want to let the user to type in something. That table will never be big (I'm guessing 15 items max).
I tried playing with the .Text property but it's not working.
-
Re: Custom Combo Box
I don't understand exactly how you want the user to select a value, but maybe this will help.
You can use a DataView object. This object get a DataTable in the constructor, and it will show values from that table.
In order to use it, here is a sample:
Code:
Dim dv As DataView = New DataView(myDataSet.Tables("MyTable"))
comboBox1.DataSource = dv
comboBox1.DisplayMember = "Name" 'Will display the Name column of MyTable table.
comboBox1.ValueMember = "Id" 'The SelectedValue property will be the Id
Set the DropDownStyle to DropDownList if you don't want the user to type values.
Now for the interesting part. The DataView object has a Filter property. by setting it you can manipulate with the list that is shown when the user sees the drop down.
Code:
dv.Filter = "" ' No Filter
'Or
dv.Filter = "Activated = True" ' You can use "Activated" (boolean)
I hope this helps.