ListBox Code to ListView!

Posts 1–15 of 21 · Page 1 of 2
ListBox Code to ListView!
This is a code made for a listbox in vb.net but I can not convert it to use with a listview cause listview does not have selectedindex. I need help converting this.

Code:
        Dim str As String = Web.DownloadString("")
        If ListBox1.SelectedIndex = ListBox1.Items.Count - 1 Then

            Dim x1 As Integer = str.IndexOf(ListBox1.SelectedItem, 0) + ListBox1.SelectedItem.ToString.Length + 1
            Dim MJ As String = Mid(str, x1).Trim

            TextBox1.Text = MJ

        Else
            Dim x1 As Integer = str.IndexOf(ListBox1.SelectedItem, 0) + ListBox1.SelectedItem.ToString.Length + 1
            Dim x2 As Integer = str.IndexOf(ListBox1.Items(ListBox1.SelectedIndex + 1), x1) + 1
            Dim MJ As String = Mid(str, x1, x2 - x1).Trim
            TextBox1.Text = MJ
        End If
Quote Originally Posted by ipwnuuaal5 View Post
This is a code made for a listbox in vb.net but I can not convert it to use with a listview cause listview does not have selectedindex. I need help converting this.

Code:
        Dim str As String = Web.DownloadString("")
        If ListBox1.SelectedIndex = ListBox1.Items.Count - 1 Then

            Dim x1 As Integer = str.IndexOf(ListBox1.SelectedItem, 0) + ListBox1.SelectedItem.ToString.Length + 1
            Dim MJ As String = Mid(str, x1).Trim

            TextBox1.Text = MJ

        Else
            Dim x1 As Integer = str.IndexOf(ListBox1.SelectedItem, 0) + ListBox1.SelectedItem.ToString.Length + 1
            Dim x2 As Integer = str.IndexOf(ListBox1.Items(ListBox1.SelectedIndex + 1), x1) + 1
            Dim MJ As String = Mid(str, x1, x2 - x1).Trim
            TextBox1.Text = MJ
        End If

Lol is that code Hassan's (Xscapism)? Seems like his style (x1. x2, x3, MJ)

Could you please provide a description of what it is that you're trying to achieve here, would make things easier as at the moment what you're attempting to achieve is fairly general without knowing the context. I think I know roughly what you want to do, I'm still in school atm so I have no IDE and won't be home for another 2 hours.
Quote Originally Posted by ipwnuuaal5 View Post
This is a code made for a listbox in vb.net but I can not convert it to use with a listview cause listview does not have selectedindex. I need help converting this.

Code:
        Dim str As String = Web.DownloadString("")
        If ListBox1.SelectedIndex = ListBox1.Items.Count - 1 Then

            Dim x1 As Integer = str.IndexOf(ListBox1.SelectedItem, 0) + ListBox1.SelectedItem.ToString.Length + 1
            Dim MJ As String = Mid(str, x1).Trim

            TextBox1.Text = MJ

        Else
            Dim x1 As Integer = str.IndexOf(ListBox1.SelectedItem, 0) + ListBox1.SelectedItem.ToString.Length + 1
            Dim x2 As Integer = str.IndexOf(ListBox1.Items(ListBox1.SelectedIndex + 1), x1) + 1
            Dim MJ As String = Mid(str, x1, x2 - x1).Trim
            TextBox1.Text = MJ
        End If
Welcome back ppl2pass

I am a bit confused with what you are trying to do. I will be on msn in 3-4 hours (Currently at univ). See ya there xD ! (Check ur PM, Replied)

Btw, now a days I have a water boy that answers when I am busy xD !
Quote Originally Posted by Hassan View Post
Now i have a water boy that answers when I am busy xD !
/me

Although I've been here for months
Quote Originally Posted by Hassan View Post


Welcome back ppl2pass

I am a bit confused with what you are trying to do. I will be on msn in 3-4 hours (Currently at univ). See ya there xD ! (Check ur PM, Replied)

Btw, now a days I have a water boy that answers when I am busy xD !
Bascially convert the listbox in this code to listview but since listview doesnt have some of the properties of listbox i am having trouble converting this code.
I don't understand.
Quote Originally Posted by Blubb1337 View Post
I don't understand.
Like this but this does not work:

Code:
        Dim str As String = Web.DownloadString("")
        If ListView1.SelectedIndex = ListView1.Items.Count - 1 Then

            Dim x1 As Integer = str.IndexOf(ListView1.SelectedItem, 0) + ListView1.SelectedItem.ToString.Length + 1
            Dim MJ As String = Mid(str, x1).Trim

            TextBox1.Text = MJ

        Else
            Dim x1 As Integer = str.IndexOf(ListView1.SelectedItem, 0) + ListView1.SelectedItem.ToString.Length + 1
            Dim x2 As Integer = str.IndexOf(ListBox1.Items(ListView1.SelectedIndex + 1), x1) + 1
            Dim MJ As String = Mid(str, x1, x2 - x1).Trim
            TextBox1.Text = MJ
        End If
ListView class/object (control) contains different members inside it...

use SelectedIndices(0)... which is the first selected item, in case you have multiple selection active, then you have to code it differently..
What Brinuz says is true, but do you not understand that we're asking for the POINT of this code, not merely reading and converting. If you tell us what it's SUPPOSED to do (in plain English, not saying "just convert it"), we'll be able to create a solution quite quickly.
Quote Originally Posted by Jason View Post
What Brinuz says is true, but do you not understand that we're asking for the POINT of this code, not merely reading and converting. If you tell us what it's SUPPOSED to do (in plain English, not saying "just convert it"), we'll be able to create a solution quite quickly.
well maybe he just wants a different control / dunno..
Quote Originally Posted by 'Bruno View Post
well maybe he just wants a different control / dunno..
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]
Quote Originally Posted by ipwnuuaal5 View Post
Like this but this does not work:

Code:
Dim str As String = Web.DownloadString("")
        If ListView1.SelectedIndex = ListView1.Items.Count - 1 Then

            Dim x1 As Integer = str.IndexOf(ListView1.SelectedItem, 0) + ListView1.SelectedItem.ToString.Length + 1
            Dim MJ As String = Mid(str, x1).Trim

            TextBox1.Text = MJ

        Else
            Dim x1 As Integer = str.IndexOf(ListView1.SelectedItem, 0) + ListView1.SelectedItem.ToString.Length + 1
            Dim x2 As Integer = str.IndexOf(ListBox1.Items(ListView1.SelectedIndex + 1), x1) + 1
            Dim MJ As String = Mid(str, x1, x2 - x1).Trim
            TextBox1.Text = MJ
        End If
Basically what Brinuz said !!

Try this:

Code:
If n.SelectedIndices(0) = n.Items.Count - 1 Then
Dim x1 As Integer = str.IndexOf(ListView1.Selecteditems(0),0) + ListView1.Selecteditems(0).ToString.Length + 1
             Dim MJ As String = Mid(str, x1).Trim
             TextBox1.Text = MJ
Else
  Dim x1 As Integer = str.IndexOf(ListView1.SelectedItems(0), 0) + ListView1.SelectedItems(0).ToString.Length + 1
Dim x2 As Integer =  str.IndexOf(Listview1.Items(ListView1.SelectedIndices(0) + 1), x1) + 1
  Dim MJ As String = Mid(str, x1, x2 - x1).Trim
TextBox1.Text = MJ
End If
I think this would work, but anyways let me know !
Quote Originally Posted by Hassan View Post


Basically what Brinuz said !!

Try this:

Code:
If n.SelectedIndices(0) = n.Items.Count - 1 Then
Dim x1 As Integer = str.IndexOf(ListView1.Selecteditems(0),0) + ListView1.Selecteditems(0).ToString.Length + 1
             Dim MJ As String = Mid(str, x1).Trim
             TextBox1.Text = MJ
Else
  Dim x1 As Integer = str.IndexOf(ListView1.SelectedItems(0), 0) + ListView1.SelectedItems(0).ToString.Length + 1
Dim x2 As Integer =  str.IndexOf(Listview1.Items(ListView1.SelectedIndices(0) + 1), x1) + 1
  Dim MJ As String = Mid(str, x1, x2 - x1).Trim
TextBox1.Text = MJ
End If
I think this would work, but anyways let me know !
I get three same errors:
Code:
Error    1    Overload resolution failed because no accessible 'IndexOf' can be called with these arguments:
    'Public Function IndexOf(value As String, comparisonType As System.StringComparison) As Integer': Value of type 'System.Windows.Forms.ListViewItem' cannot be converted to 'String'.
    'Public Function IndexOf(value As String, startIndex As Integer) As Integer': Value of type 'System.Windows.Forms.ListViewItem' cannot be converted to 'String'.
    'Public Function IndexOf(value As Char, startIndex As Integer) As Integer': Value of type 'System.Windows.Forms.ListViewItem' cannot be converted to 'Char'.


----
edit and for jason`s code i get the same error on this line:
Code:
Dim x2 As Integer = str.IndexOf(ListView1.Items(lvIndex + 1), x1) + 1
Quote Originally Posted by ipwnuuaal5 View Post
I get three same errors:
Code:
Error    1    Overload resolution failed because no accessible 'IndexOf' can be called with these arguments:
    'Public Function IndexOf(value As String, comparisonType As System.StringComparison) As Integer': Value of type 'System.Windows.Forms.ListViewItem' cannot be converted to 'String'.
    'Public Function IndexOf(value As String, startIndex As Integer) As Integer': Value of type 'System.Windows.Forms.ListViewItem' cannot be converted to 'String'.
    'Public Function IndexOf(value As Char, startIndex As Integer) As Integer': Value of type 'System.Windows.Forms.ListViewItem' cannot be converted to 'Char'.


----
edit and for jason`s code i get the same error on this line:
Code:
Dim x2 As Integer = str.IndexOf(ListView1.Items(lvIndex + 1), x1) + 1

Try this one:

Code:
If n.SelectedIndices(0) = n.Items.Count - 1 Then
            Dim x1 As Integer = str.IndexOf(lv.SelectedItems(0).Text, 0) + lv.SelectedItems(0).ToString.Length + 1
            Dim MJ As String = Mid(str, x1).Trim
            TextBox1.Text = MJ
        Else
            Dim x1 As Integer = str.IndexOf(lv.SelectedItems(0).Text, 0) + lv.SelectedItems(0).Text.ToString.Length + 1
            Dim x2 As Integer = str.IndexOf(lv.SelectedItems(0).Text, x1) + 2
            Dim MJ As String = Mid(str, x1, x2 - x1).Trim
            TextBox1.Text = MJ
        End If
If it fails for you, then post your problem. Will rewrite the solution !!!
Quote Originally Posted by Hassan View Post



Try this one:

Code:
If n.SelectedIndices(0) = n.Items.Count - 1 Then
            Dim x1 As Integer = str.IndexOf(lv.SelectedItems(0).Text, 0) + lv.SelectedItems(0).ToString.Length + 1
            Dim MJ As String = Mid(str, x1).Trim
            TextBox1.Text = MJ
        Else
            Dim x1 As Integer = str.IndexOf(lv.SelectedItems(0).Text, 0) + lv.SelectedItems(0).Text.ToString.Length + 1
            Dim x2 As Integer = str.IndexOf(lv.SelectedItems(0).Text, x1) + 2
            Dim MJ As String = Mid(str, x1, x2 - x1).Trim
            TextBox1.Text = MJ
        End If
If it fails for you, then post your problem. Will rewrite the solution !!!
Code not working. I will explain everything on msn.
Posts 1–15 of 21 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?