ListBox Code to ListView!

Posts 16–21 of 21 · Page 2 of 2
Quote Originally Posted by Jason View Post


I know that, but I mean what was his code designed to do in the first place?

Edit, if you want to get the currently selected item and it's index...

Globals:
[php]
Private lvItem As ListViewItem
Private lvIndex As Integer = 0
[/php]

Then add this to substantiate those items:
[php]
Private Sub ListView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseClick
lvItem = ListView1.GetItemAt(e.X, e.Y)
lvIndex = ListView1.Items.IndexOf(lvItem)
End Sub
[/php]

Then change your original code to this:
[php]
If not lvItem is nothing then
Dim str As String = Web.DownloadString("")
If lvIndex = ListView1.Items.Count - 1 Then

Dim x1 As Integer = str.IndexOf(lvItem.Text, 0) + lvItem.Text.Length + 1
Dim MJ As String = Mid(str, x1).Trim

TextBox1.Text = MJ

Else
Dim x1 As Integer = str.IndexOf(lvItem.Text, 0) + lvItem.Text.Length + 1
Dim x2 As Integer = str.IndexOf(ListView1.Items(lvIndex + 1), x1) + 1
Dim MJ As String = Mid(str, x1, x2 - x1).Trim
TextBox1.Text = MJ
End If
End if
[/php]
Error on this line:
Dim x2 As Integer = str.IndexOf(ListView1.Items(lvIndex + 1), x1) + 1
Quote Originally Posted by ipwnuuaal5 View Post
Error on this line:
Ahh, my mistake.

[php]
If not lvItem is nothing then
Dim str As String = Web.DownloadString("")
If lvIndex = ListView1.Items.Count - 1 Then

Dim x1 As Integer = str.IndexOf(lvItem.Text, 0) + lvItem.Text.Length + 1
Dim MJ As String = Mid(str, x1).Trim

TextBox1.Text = MJ

Else
Dim x1 As Integer = str.IndexOf(lvItem.Text, 0) + lvItem.Text.Length + 1
Dim x2 As Integer = str.IndexOf(ListView1.Items(lvIndex + 1).Text, x1) + 1
Dim MJ As String = Mid(str, x1, x2 - x1).Trim
TextBox1.Text = MJ
End If
End if
[/php]

Should probably fix it up. I didn't actually test any of this, just wrote it out in my reply haha. Forgot to select the text property.
Maybe I shouldn't leave

Code:
Private Sub ListView_SelectedIndexChanged(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Listview1.SelectedIndexChanged
        Dim SelectedItems As ListView.SelectedListViewItemCollection = _
            CType(sender, ListView).SelectedItems

        If (SelectedItems.Count > 0) Then
            ' What you want to happen here
       ' In your case, MJ yada yada
       Else
        'Yada yada
        End If
End Sub
Change listview1 to your listview name,

Should work, That's one of those MSDN Standards
Quote Originally Posted by NextGen1 View Post
Maybe I shouldn't leave

Code:
Private Sub ListView_SelectedIndexChanged(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Listview1.SelectedIndexChanged
        Dim SelectedItems As ListView.SelectedListViewItemCollection = _
            CType(sender, ListView).SelectedItems

        If (SelectedItems.Count > 0) Then
            ' What you want to happen here
       ' In your case, MJ yada yada
       Else
        'Yada yada
        End If
End Sub
Change listview1 to your listview name,

Should work, That's one of those MSDN Standards
OMG LOL, that's not his problem xD !
Oh, Thought he was looking to get selected, I din't read much of anything really....

/RageQuits
Quote Originally Posted by NextGen1 View Post
Oh, Thought he was looking to get selected, I din't read much of anything really....

/RageQuits
Come back! I forgive you
Posts 16–21 of 21 · Page 2 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us