Results 1 to 3 of 3

Thread: [HELP] Split In ListBox

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2015
    Posts
    1

    [HELP] Split In ListBox

    I want make if listbox item double click then message show with the content
    Name:  ask.png
Views: 259
Size:  1.8 KB
    How do I divide into 2 strings ?
    [TIME] Is String 1
    And after text [TIME] Is String 2

  2. #2
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: [HELP] Split In ListBox

    You should really do this in an object orientated way. You add the object into the listbox, and take it back out.

  3. #3
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,534

    Re: [HELP] Split In ListBox

    Here is one method where we populate the ListBox with a DataTable, get information back then remove a row. I kept things simple which can easily be expanded upon.

    Code:
    Private Sub LoadListBox()
        Dim dt As New DataTable
        dt.Columns.Add(New DataColumn With
                       {.ColumnName = "LeftSide", .DataType = GetType(String)})
        dt.Columns.Add(New DataColumn With
                       {.ColumnName = "RightSide", .DataType = GetType(String)})
        dt.Columns.Add(New DataColumn With
                       {.ColumnName = "DisplayText", .DataType = GetType(String),
                        .Expression = "LeftSide + '  ' + RightSide"})
        dt.Rows.Add(New Object() {"[" & Now.ToString & "]", "A"})
        ListBox1.DataSource = dt
        ListBox1.DisplayMember = "DisplayText"
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        LoadListBox()
        Dim dt As DataTable = CType(ListBox1.DataSource, DataTable)
        dt.Rows.Add(New Object() {"[" & Now.AddHours(1).ToString & "]", "B"})
        MessageBox.Show(CType(ListBox1.Items(0), DataRowView). _
                Row.Field(Of String)("LeftSide").Replace("[", "").Replace("]", ""))
        dt.Rows.RemoveAt(0)
    End Sub

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