-
Apr 23rd, 2006, 02:19 PM
#1
Thread Starter
Junior Member
checking if an ITEM already exists in a listview
Sorry wrong forum -> should be VS 2005 instead of classic vb
hi,
I'm currenly trying to load two textfiles in a listview.
afterwards i'm updating one of the columns where i have the following problem
i donnot know if a certain index of the item already exist
so for instance i want to update a subitem but i donnot know if the item itself exists.
the method
listview.item(2).exists
does not seem to exist
is there another way ?
-
Apr 23rd, 2006, 02:48 PM
#2
Re: checking if an ITEM already exists in a listview
Originally Posted by sjorsmiltenburg
Sorry wrong forum -> should be VS 2005 instead of classic vb
Moved
-
Apr 23rd, 2006, 06:38 PM
#3
Re: checking if an ITEM already exists in a listview
I'm not quite sure what you're asking. Are you saying that you want to know if the number of items in a ListView is at least a certain number? If so then you use the Count property like you do with every collection:
VB Code:
If myListView.Items.Count >= 3 Then
'There is an item at index 2.
End If
-
Apr 26th, 2006, 03:53 PM
#4
Thread Starter
Junior Member
Re: checking if an ITEM already exists in a listview
sorry for the slow update, but this is my problem
i'm trying to use the same function to initially fill in a column with the lines from the textfile and afterwards i'm trying to use the same function to update one of the columns (i want to switch textfile and therefore update all the lines in one of the columns)
this is my code
VB Code:
Private Function AppendLinesToColumn(ByVal ListViewColumnIndex As Integer, ByVal FilePath As String, ByVal FirstItemIndex As Integer) As Boolean
Dim SR As StreamReader
Dim NextItemIndex As Integer = FirstItemIndex
If File.Exists(FilePath) = True Then
SR = File.OpenText(FilePath)
Dim MyText As String = SR.ReadToEnd
Dim MyLines() As String = Strings.Split(MyText, Environment.NewLine) 'splits on newline character, into a strings array containg all the lines
SR.Close()
For Each strContents As String In MyLines
'insert data of first column "nr"
If ListView1.Items.Count <= NextItemIndex Then
ListView1.Items.Add(NextItemIndex)
ListView1.Items(NextItemIndex).SubItems.Add(strContents)
Else if
ListView1.Items(NextItemIndex).SubItems(ListViewColumnIndex).Text = strContents
End If
'insert data in other column
ListView1.Update()
NextItemIndex += 1
Next
Return NextItemIndex - 1
Else
MsgBox("Error reading file " & FilePath & ".")
Return False
End If
End Function
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
|