1 Attachment(s)
VB2008 How to search items in listview using combobox
Good day!.. I'm having a hard time on how to search items in listview, wherein if I choose items in combo box, it will displays the items that I search. I'm also using database, I have here my output.. Can someone help me?. I will appreciate any suggestions or comments, Thank You and God Bless..
Attachment 102883
Re: VB2008 How to search items in listview using combobox
Re: VB2008 How to search items in listview using combobox
Sir. I'm using Visual Basic 2008 sir, not vb.net
:D
Re: VB2008 How to search items in listview using combobox
So you are using vb.net then. You don't t need to include 2008 or even the .net suffix. 2008 is simply the version.
Re: VB2008 How to search items in listview using combobox
i see.. so can you help me? i have here my codes
Quote:
For index As Integer = ListView1.Items.Count - 1 To 0 Step -1
If ListView1.Items(index).SubItems(1).Text <> cboCollege.Text Then
ListView1.Items.RemoveAt(index)
End If
Next index
but the problem is, if i try another search, the listview doesn't refresing its list. and the items that I search didn't appear..
Re: VB2008 How to search items in listview using combobox
i see.. so can you help me? i have here my codes
Quote:
For index As Integer = ListView1.Items.Count - 1 To 0 Step -1
If ListView1.Items(index).SubItems(1).Text <> cboCollege.Text Then
ListView1.Items.RemoveAt(index)
End If
Next index
but the problem is, if i try another search, the listview doesn't refresing its list. and the items that I search didn't appear..
Re: VB2008 How to search items in listview using combobox
Hi,
Quote:
i see.. so can you help me? i have here my codes
Quote:
For index As Integer = ListView1.Items.Count - 1 To 0 Step -1
If ListView1.Items(index).SubItems(1).Text <> cboCollege.Text Then
ListView1.Items.RemoveAt(index)
End If
Next index
but the problem is, if i try another search, the listview doesn't refresing its list. and the items that I search didn't appear..
You cannot use a ListView in this way. The listView is a standalone collection of ListViewItems and once you remove an item from the ListView it is gone forever until you replace it.
If you want to continue to use a ListView to display the results of your searches then what you need to do is interrogate the original Data Source in your project to select the records that fit your ComboBox's criteria, clear the existing list of ListViewItems in the ListView and then finally re-add the ListViewItems that match the selected criteria.
Alternatively, and since you have mentioned that you are using a Database, I would suggest that you create a BindingSource with its DataSource set to the necessary DataTable in your project and then set that BindingSource to the DataSource of a DataGridView.
You can then use the Filter property of the BindingSource to limit the information displayed in the DataGridView based on the necessary criteria of your ComboBox's.
For more information on the BindingSource.Filter property, have a look here:-
http://msdn.microsoft.com/en-us/libr...v=vs.100).aspx
Hope that helps.
Cheers,
Ian
Re: VB2008 How to search items in listview using combobox
Quote:
Originally Posted by
IanRyder
Hi,
You cannot use a ListView in this way. The listView is a standalone collection of ListViewItems and once you remove an item from the ListView it is gone forever until you replace it.
If you want to continue to use a ListView to display the results of your searches then what you need to do is interrogate the original Data Source in your project to select the records that fit your ComboBox's criteria, clear the existing list of ListViewItems in the ListView and then finally re-add the ListViewItems that match the selected criteria.
Alternatively, and since you have mentioned that you are using a Database, I would suggest that you create a BindingSource with its DataSource set to the necessary DataTable in your project and then set that BindingSource to the DataSource of a DataGridView.
You can then use the
Filter property of the BindingSource to limit the information displayed in the DataGridView based on the necessary criteria of your ComboBox's.
For more information on the BindingSource.Filter property, have a look here:-
http://msdn.microsoft.com/en-us/libr...v=vs.100).aspx
Hope that helps.
Cheers,
Ian
Thanks Ian, but, is it okay to create BindingSource while using this codes in my module?
Module Module1
Public cn As ADODB.Connection
Public rs As ADODB.Recordset
Public Sub connection()
cn = New ADODB.Connection
With cn
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Information.accdb"
.CursorLocation = ADODB.CursorLocationEnum.adUseClient
.Open()
End With
End Sub
End Module