-
Feb 18th, 2014, 12:15 AM
#1
Thread Starter
Member
FindItemWithText in listview results in other listview
hi everyone..
I tried the both events.. but the result is always the same. I have two listview(lvMessage and lvContact)
lvMessage (1st lisview - Items are from sim card)
index 0 | Null
index 1 | Cell Number - (lets say i have {"1234", "2468"})
index 2 | Date and Time
index 3 | Message
lvContact(2nd listview)
index 0 | ID
index 1 | Name - (lets say i have {"Chris", "Mark", "Cedric"})
index 2 | Number - (lets say i have {"1234", "2468"})
here is my Code:
Code:
Dim ChkContact As New ListViewItem
Dim TheText As ListViewItem = Me.lvMessage.Items(0)
ChkContact = lvContact2.FindItemWithText(TheText.SubItems(1).Text.ToString)
If ChkContact IsNot Nothing Then
txtContact.Text = ChkContact.SubItems(1).Text
lvMessage.FocusedItem.SubItems(0).Text = ChkContact.SubItems(1).Text
Else
txtContact.Text = "no match found"
lvMessage.FocusedItem.SubItems(0).Text = "Not in the list"
End If
the result in txtContact.text and index(0) in my 1st listview(lvMessage) is "Chris"
even I click or checked other rows the result is always "Chris" in index 0
please help.. I know the code is working in FindItemWithText but the result I want is always the same...
thanks
-
Feb 18th, 2014, 12:24 AM
#2
Re: FindItemWithText in listview results in other listview
You're always getting the text to search for from the same place so it will always be the same text, so why would the result not be the same every time? Maybe you should provide an explanation of what you're actually trying to achieve instead of expecting us to work it out from code that doesn't actually achieve it. We can't just read your mind and I for one am not interested in guessing or trying to work out something that you already know.
-
Feb 18th, 2014, 03:37 AM
#3
Thread Starter
Member
Re: FindItemWithText in listview results in other listview
You're always getting the text to search for from the same place so it will always be the same text, so why would the result not be the same every time?
yeah I think I was... (been thinking how not to do that.. So I ask for help)...
-
Feb 18th, 2014, 03:49 AM
#4
Re: FindItemWithText in listview results in other listview
You're still expecting us to read your mind. If you don't want to use the same text every time then don't. Where do you want to get the text from? It's your project; you tell us.
-
Feb 18th, 2014, 04:48 AM
#5
Thread Starter
Member
Re: FindItemWithText in listview results in other listview
I changed my code to this...
Code:
Private Sub LvMessage_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LvMessage.SelectedIndexChanged
Try
Dim ChkContact As New ListViewItem
Dim TheText As ListViewItem = Me.LvMessage.SelectedItems(0)
ChkContact = lvContact2.FindItemWithText(TheText.SubItems(1).Text.ToString)
If ChkContact IsNot Nothing Then
txtContact.Text = ChkContact.SubItems(1).Text
LvMessage.FocusedItem.SubItems(0).Text = ChkContact.SubItems(1).Text
Else
txtContact.Text = "no match found"
ListView2.FocusedItem.SubItems(0).Text = "Not in the list"
End If
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
i got this error
invalidArgument = Value of '0' is not valid for 'index'
parameter name: index
Where do you want to get the text from?
I'm getting the text to search from LvMessage(my 1st Listview) subitem(1)... that text will be search in my 2nd listview(lvContact)..
-
Feb 18th, 2014, 12:59 PM
#6
Re: FindItemWithText in listview results in other listview
Originally Posted by chrisTemper
I'm getting the text to search from LvMessage(my 1st Listview) subitem(1)... that text will be search in my 2nd listview(lvContact)..
From what your showing as the items the only possible match between the two LV's seems to be the cell numbers, and going by your other threads on this same question I think you wanted to copy the persons name in one LV when you find their matching cell number into the text column (subitem(0)) of the other LV?, If true then this worked for me. I made extra variables to hopefully make it easier to follow (or modify).
' ListView Test Data
Code:
lvMessage.Items.Add(New ListViewItem({"", "123-4567", "Jan 1 2014", "message-A"}))
lvMessage.Items.Add(New ListViewItem({"", "789-1234", "Jan 2 2014", "message-B"}))
lvMessage.Items.Add(New ListViewItem({"", "456-7890", "Jan 3 2014", "message-C"}))
lvContact.Items.Add(New ListViewItem({"ID:1", "Chris", "789-1234"}))
lvContact.Items.Add(New ListViewItem({"ID:2", "Mark", "456-7890"}))
lvContact.Items.Add(New ListViewItem({"ID:3", "Cedric", "123-4567"}))
Code:
' make sure a LV lvmessage has item selected
If lvMessage.SelectedIndices.Count > 0 Then
' get the first selected lvi
Dim lviMsgSelected As ListViewItem = Me.lvMessage.SelectedItems(0)
' get cell number text from the first selected lvi
Dim strMsgSelected_CellNumber As String = lviMsgSelected.SubItems(1).Text
' find matching cell number in LV lvContact
Dim lviFindCell = lvContact.FindItemWithText(strMsgSelected_CellNumber)
' Did we find a match?
If lviFindCell IsNot Nothing Then
' Get the persons name
Dim strPersonName As String = lviFindCell.SubItems(1).Text
' copy the name to LV lvMessage text column.
lviMsgSelected.Text = strPersonName
Else
MessageBox.Show("No match found")
End If
Else
MessageBox.Show("Nothing selected in lvMessage")
End If
If this doesn't help or isn't what you're trying to do then please post a clear & complete description, and possibly even a demo project of what you need help with.
Last edited by Edgemeal; Feb 18th, 2014 at 01:02 PM.
Tags for this Thread
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
|