473,757 Members | 10,736 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6305
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(By Val 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.Co unt - 1) As String
Do Until j = FieldNames.Coun t
If Not
IsDBNull(DataTa ble.Rows(i).Ite m(FieldNames(j) .ToString)) Then
s(j) =
DataTable.Rows( i).Item(FieldNa mes(j).ToString ).ToString
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*****@discus sions.microsoft .com> schrieb im Newsbeitrag
news:C1******** *************** ***********@mic rosoft.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(By Val 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.Co unt - 1) As String
Do Until j = FieldNames.Coun t
If Not
IsDBNull(DataTa ble.Rows(i).Ite m(FieldNames(j) .ToString)) Then
s(j) =
DataTable.Rows( i).Item(FieldNa mes(j).ToString ).ToString
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 RemoveDoubleEnt ries(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.I tems.Count)

'List read
For i1 = 0 To LBox.Items.Coun t - 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.Clea r()
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
7960
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
23935
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, for example, a list of town names, but there are hundreds of duplicates, like: "Aberdeen Aberdeen Aberdeen Edinburg Edinburg Inverness etc."
4
4767
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 the email address)
7
10415
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, while they are added to the treeview without the path (only file name). I'd like the user would be able to remove multiple items selecting filenames from the listview. So, items should be removed both from the listview and the treeview. How can I do...
14
21980
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 entries - all exactly the same, except the event_id field, which is auto-numbered. I need a way to query the record w/out duplicates. That is, any records exactly the same except event_id should only return one record. Is this possible??
7
2032
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
3940
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 the ListView or not. The natural place to inspect this is in the AfterLabelEdit event... If the decision is to take the item out, I used the ListViewItem.Remove(). However - check this out: A) say that the item's index is N (indices are...
2
12334
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
5096
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 simple program that illustrates the exception is below: using System; using System.Windows.Forms; namespace WindowsApplication1
0
9489
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10072
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9737
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.