Results 1 to 3 of 3

Thread: How to return and separate values from listbox?

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    49

    How to return and separate values from listbox?

    Name:  example.png
Views: 123
Size:  12.7 KB
    Code:
    Public Class Form1
    '//Add button
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            ListBox1.Items.Add("a=" & TextBox1.Text & " " & "b=" & TextBox2.Text & " " & "c=" & TextBox3.Text)
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
     
        End Sub
    '//Remove button
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            ListBox1.Items.Remove(ListBox1.SelectedItem)
        End Sub
     
    '//Edit button
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            TextBox1.Text = ListBox1.SelectedItem()'//There is a problem because it returns all values into one textbox and I just wanna to separate values just like in input
        End Sub

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: How to return and separate values from listbox?

    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3
    Fanatic Member ThomasJohnsen's Avatar
    Join Date
    Jul 2010
    Location
    Denmark
    Posts
    528

    Re: How to return and separate values from listbox?

    Or as usual there's allways the Regex-route (remember to import System.Text.RegularExpressions):
    vb.net Code:
    1. Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    2.  
    3.         Static reg As New Regex("^a=(?<a>.*)\sb=(?<b>.*)\sc=(?<c>.*)$", RegexOptions.Compiled)
    4.         Dim m As Match = reg.Match(ListBox1.SelectedItem)
    5.  
    6.         If m.Success Then
    7.             TextBox1.Text = m.Groups(1).Value
    8.             TextBox2.Text = m.Groups(2).Value
    9.             TextBox3.Text = m.Groups(3).Value
    10.         End If
    11.  
    12.     End Sub

    Regards Tom
    In truth, a mature man who uses hair-oil, unless medicinally , that man has probably got a quoggy spot in him somewhere. As a general rule, he can't amount to much in his totality. (Melville: Moby Dick)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width