I am trying to create some filters to display the matching results from a table.
I am not using a traditional database, all data is from a text file.
Currently I have multiple tables that the user can choose from but all tables contain the same columns, for example "Category".
When the user selects which table they want, that table is loaded, a unique list of categories is created in a list of strings which is then sorted and added to a combobox.
Before the list is added to the combobox an entry is added.
CB_Categories.Items.Add("")
For i = 0 To StrCategories.Count - 1
If StrCategories(i) <> "" Then
CB_Categories.Items.Add(StrCategories(i))
End If
Next
This code works correctly.
If this empty or blank entry is selected then all entries are displayed, which is how I want it to work.
My problem is that I wanted to display something in the combobox that tells the user that ALL categories will be displayed instead of having a blank display.
So I need to have a combobox that has two columns, a hidden column that contains the values , and the other contains the text to display to the user.
I tried searching and found many posts on how to do this using a database, but these were of no use to me since I am not using a database.
There were other examples that placed a datagridview under the combobox, but I didn't like this approach.
I tried making a two column table from this list of strings that contained the values in one column and the text in the other and then binding it to the combobox with the display member set to the text and the value member set to the value.
Tbl_Categories.Rows.Add("", "All")
For i = 0 To StrCategories.Count - 1
If StrCategories(i) <> "" Then
Tbl_Categories.Rows.Add(StrCategories(i), StrCategories(i))
End If
Next
For appearance this was perfect, but it didn't work because when "All" was selected the filter no longer showed all entries, but instead was looking for entries that had nothing as their category.
If I could get that to work then I would be happy.
I don't know if you can do something like "if it isn't null then display it". I think that would show everything, including an empty string.
Apparently there is something different between adding "" directly to a combobox compared to adding it to a row in a table. I think when adding it to a combobox you add a value but when adding to a table you are adding text.
I have code in the app that shows a combobox with a colored rectangle, an ID number and a color name, I had help creating this.
I tried to copy and modify it for the categories but due to a current lack of understanding I was unable to get it to work.
Because of this color combobox I am sure there is a way to create a combobox that displays one list and works off a second hidden list of values, but I don't know how to do it.
Does anybody know how to create such a combobox from a list of strings?