"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