1 Attachment(s)
How to return and separate values from listbox?
Attachment 93109
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
Re: How to return and separate values from listbox?
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:
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Static reg As New Regex("^a=(?<a>.*)\sb=(?<b>.*)\sc=(?<c>.*)$", RegexOptions.Compiled)
Dim m As Match = reg.Match(ListBox1.SelectedItem)
If m.Success Then
TextBox1.Text = m.Groups(1).Value
TextBox2.Text = m.Groups(2).Value
TextBox3.Text = m.Groups(3).Value
End If
End Sub
Regards Tom