473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Remove duplicates in listview in VB.NET

Hi

I have an application with listview.When i click on one
button the data will be displayed like this in the
listview:
colA colB colC
----- ----- ------
nannacom.com 0 0

When i click on another button,i want to display like this
in the same list view:
colA colB colC
----- ----- ------
nannacom.com 2 5

How can i replace the first one with the second one.
I displayed data into listview from database.

If any one knows the solution please let me know.
Thakns in advance.

Mamatha
Nov 21 '05 #1
2 6257
You could create separate Datatables for the data you want displayed from
each Button click. The following method comes from a project I recently
completed.

Parameter Info:

ListView is the ListView you are filling. DataTable provides the data.
Columns is an ArrayList that provides the names of the fields from the
Datatable that you want to include in the ListView. If you know that you
would always want to use all fields, you could remove the ArrayList
parameter, and modify the code.

Public Sub FillListView(ByVal ListView As ListView, _
ByVal DataTable As DataTable, ByVal FieldNames As ArrayList)
ListView.Items.Clear()
Dim i As Int32
Dim j As Int32
Dim LVI As ListViewItem
Do Until i = DataTable.Rows.Count
j = 0
Dim s(FieldNames.Count - 1) As String
Do Until j = FieldNames.Count
If Not
IsDBNull(DataTable.Rows(i).Item(FieldNames(j).ToSt ring)) Then
s(j) =
DataTable.Rows(i).Item(FieldNames(j).ToString).ToS tring
Else
s(j) = ""
End If
j += 1
Loop
LVI = New ListViewItem(s)
ListView.Items.Add(LVI)
i += 1
Loop
End Sub
www.charlesfarriersoftware.com
"Mamatha" wrote:
Hi

I have an application with listview.When i click on one
button the data will be displayed like this in the
listview:
colA colB colC
----- ----- ------
nannacom.com 0 0

When i click on another button,i want to display like this
in the same list view:
colA colB colC
----- ----- ------
nannacom.com 2 5

How can i replace the first one with the second one.
I displayed data into listview from database.

If any one knows the solution please let me know.
Thakns in advance.

Mamatha

Nov 21 '05 #2

"Charlie" <Ch*****@discussions.microsoft.com> schrieb im Newsbeitrag
news:C1**********************************@microsof t.com...
You could create separate Datatables for the data you want displayed from
each Button click. The following method comes from a project I recently
completed.

Parameter Info:

ListView is the ListView you are filling. DataTable provides the data.
Columns is an ArrayList that provides the names of the fields from the
Datatable that you want to include in the ListView. If you know that you
would always want to use all fields, you could remove the ArrayList
parameter, and modify the code.

Public Sub FillListView(ByVal ListView As ListView, _
ByVal DataTable As DataTable, ByVal FieldNames As ArrayList)
ListView.Items.Clear()
Dim i As Int32
Dim j As Int32
Dim LVI As ListViewItem
Do Until i = DataTable.Rows.Count
j = 0
Dim s(FieldNames.Count - 1) As String
Do Until j = FieldNames.Count
If Not
IsDBNull(DataTable.Rows(i).Item(FieldNames(j).ToSt ring)) Then
s(j) =
DataTable.Rows(i).Item(FieldNames(j).ToString).ToS tring
Else
s(j) = ""
End If
j += 1
Loop
LVI = New ListViewItem(s)
ListView.Items.Add(LVI)
i += 1
Loop
End Sub


Hi Charlie, hi Mamatha,

Charlie, i think you fill the list only, here is the solution:

Private Sub RemoveDoubleEntries(ByVal LBox As ListBox)
Dim Entries1() As String
Dim Entries2() As String
Dim UB As Integer
Dim i1 As Integer
Dim i2 As Integer
Dim found As Boolean
Dim DidInit As Boolean

'Array(Data) dim the array
ReDim Entries1(LBox.Items.Count)

'List read
For i1 = 0 To LBox.Items.Count - 1
Entries1(i1) = LBox.Items.Item(i1)
Next

'All entries
For i1 = 0 To UBound(Entries1)
'Flag set
found = False

'read all entries
For i2 = 0 To UB
'Init?
If Not DidInit Then
'Wen found init a little later
found = False
Exit For
ElseIf Entries1(i1) = Entries2(i2) Then
'Double Item found!
found = True
Exit For
End If
Next

'is a double Item?
If Not found Then
'Is init done?
If Not DidInit Then
'Neue Liste auf erforderliche Größe setzen
ReDim Entries2(UBound(Entries1))
DidInit = True
End If

'Add to the new list
Entries2(UB) = Entries1(i1)

UB = UB + 1
End If
Next

'once to much
UB = UB - 1
'Restlichen Elemente abschneiden.
ReDim Preserve Entries2(UB)

'Fill listview with the new list
LBox.Items.Clear()
For i1 = 0 To UB
LBox.Items.Add(Entries2(i1))
Next
End Sub

Greeting

Thomas
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Wm | last post by:
I have a table of users in mySQL that appears to have a lot of duplicates. What's the best way to look at the userID and email and delete the duplicates? Thanx, Wm
7
by: Voetleuce en fênsievry | last post by:
Hello everyone. I'm not a JavaScript author myself, but I'm looking for a method to remove duplicate words from a piece of text. This text would presumably be pasted into a text box. I have,...
4
by: rdi | last post by:
Why does the following NOT remove the items from the ListView? I need to remove all the items and re-build the LV based on new information. Thanks. -- RDI (remove the exclamation from...
7
by: Progalex | last post by:
Hi everybody! I have a listview and a treeview in a form . With an OpenDialog I let the user select multiple files and then these files are added to the listview with the complete pathname,...
14
by: BarrySDCA | last post by:
I have a database being populated by hits to a program on a server. The problem is each client connection may require a few hits in a 1-2 second time frame. This is resulting in multiple database...
7
by: Mike Johnson | last post by:
How do I remove a item that's been selected from a listview? I'm using Visual Basic 2005 express edition. Thanks
2
by: Kela | last post by:
An interesting problem: I have a ListView with LabelEdit set to TRUE. When I change the label, I want to make some decisions as to whether the ListViewItem (that's just been edited) should stay in...
2
by: shapper | last post by:
Hello, I have an Enum and a Generic.List(Of Enum) 1 Public Enum Mode 2 Count 3 Day 4 Month 5 End Enum
1
by: dvestal | last post by:
I have a ListView with checkboxes. I want to remove items when the checkboxes are unchecked, but to do so yields an ArgumentOutOfRangeException. Is there an easy way to get around this? A...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.