-
Jul 29th, 2013, 05:43 AM
#1
Thread Starter
Member
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..
-
Jul 29th, 2013, 06:14 AM
#2
Re: VB2008 How to search items in listview using combobox
-
Jul 29th, 2013, 07:05 AM
#3
Thread Starter
Member
Re: VB2008 How to search items in listview using combobox
Sir. I'm using Visual Basic 2008 sir, not vb.net
-
Jul 29th, 2013, 07:23 AM
#4
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.
-
Jul 29th, 2013, 07:28 AM
#5
Thread Starter
Member
Re: VB2008 How to search items in listview using combobox
i see.. so can you help me? i have here my codes
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..
-
Jul 29th, 2013, 07:29 AM
#6
Thread Starter
Member
Re: VB2008 How to search items in listview using combobox
i see.. so can you help me? i have here my codes
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..
-
Jul 29th, 2013, 09:46 AM
#7
Re: VB2008 How to search items in listview using combobox
Hi,
i see.. so can you help me? i have here my codes
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
-
Jul 30th, 2013, 07:28 AM
#8
Thread Starter
Member
Re: VB2008 How to search items in listview using combobox
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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|