Howdy,
I am trying to figure out how to remove duplicate items from a list box.
This is the Code to load my list box.
Dim lbcount As Integer
Dim i As Integer
Dim lbSelected As String
If chkLBSerial.Checked = True Then
ListBox1.DataSource = DataSet1.Tables("tblPCInventory")
ListBox1.DisplayMember = "PCI_Serial"
Else
ListBox1.DataSource = DataSet1.Tables("tblPCInventory")
ListBox1.DisplayMember = "PCI_FC"
End If
And I have placed a button on the form to try and remove duplicates. I am able to get it to work with just a general collection of items, but this is loading a list from a dataset
Code for the Button is:
Dim cntr As Integer
For cntr = ListBox1.Items.Count - 1 To 1 Step -1
' If next item is a duplicate -> Remove It
If ListBox1.Items(cntr) = ListBox1.Items(cntr - 1) Then _
ListBox1.Items.RemoveAt(cntr)
Next
However I am getting the following Error Message.
Operator is not valid for type 'DataRowView' and type 'DataRowView'.
It is almost like it is trying to remove the whole row and not the item listed in the list box. I think I'll explain a bit to see if I can get some possible suggestions since this is the first time in a few years I've started programming again.
These are some of the Tables in my database, a PC_Name and a PC_History. Basically we have given all our PCs Id Names, and would like to be able to pull their history information. So I would like to populate a listbox with the names of the PCs, (easy part) removing the duplicates (where I'm stuck) and then display all of the history related to the selected PC. For Example: I click on PC-101 and it scrolls through the database collecting all of the history from PC-101 and then displays it.
I guess my concern is that I don't want it to actually delete the entire row, but just the duplicate in the listbox so I can use that as search criteria.
Thanks,
Dd.
I am trying to figure out how to remove duplicate items from a list box.
This is the Code to load my list box.
Dim lbcount As Integer
Dim i As Integer
Dim lbSelected As String
If chkLBSerial.Checked = True Then
ListBox1.DataSource = DataSet1.Tables("tblPCInventory")
ListBox1.DisplayMember = "PCI_Serial"
Else
ListBox1.DataSource = DataSet1.Tables("tblPCInventory")
ListBox1.DisplayMember = "PCI_FC"
End If
And I have placed a button on the form to try and remove duplicates. I am able to get it to work with just a general collection of items, but this is loading a list from a dataset
Code for the Button is:
Dim cntr As Integer
For cntr = ListBox1.Items.Count - 1 To 1 Step -1
' If next item is a duplicate -> Remove It
If ListBox1.Items(cntr) = ListBox1.Items(cntr - 1) Then _
ListBox1.Items.RemoveAt(cntr)
Next
However I am getting the following Error Message.
Operator is not valid for type 'DataRowView' and type 'DataRowView'.
It is almost like it is trying to remove the whole row and not the item listed in the list box. I think I'll explain a bit to see if I can get some possible suggestions since this is the first time in a few years I've started programming again.
These are some of the Tables in my database, a PC_Name and a PC_History. Basically we have given all our PCs Id Names, and would like to be able to pull their history information. So I would like to populate a listbox with the names of the PCs, (easy part) removing the duplicates (where I'm stuck) and then display all of the history related to the selected PC. For Example: I click on PC-101 and it scrolls through the database collecting all of the history from PC-101 and then displays it.
I guess my concern is that I don't want it to actually delete the entire row, but just the duplicate in the listbox so I can use that as search criteria.
Thanks,
Dd.