Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Visual Basic (https://www.askmehelpdesk.com/forumdisplay.php?f=469)
-   -   VB.NET listbox question (https://www.askmehelpdesk.com/showthread.php?t=674980)

  • Jun 25, 2012, 08:09 AM
    habydlg
    VB.NET listbox question
    Greetings,

    I need to access a certain item in a listbox and then save it to a textbox. For example, I have a listbox with 5 items and 5 textboxes, and I need one item per textbox. What is the code necessary to access individual items in a textbox?
  • Sep 28, 2012, 10:31 AM
    jsblume
    I don't know if you have an answer yet or not, but it all depends on how the data is bound to the ListBox.

    You can access a specific item in a ListBox using the Items() collection:

    ListBox.Items(0) for the first item in the list.

    If the data is an array of String:

    TextBox1.Text = ListBox.Items(0)

    If the data is a DataTable:

    TextBox1.Text = DirectCast(ListBox1.Items(0), DataRowView).Item(<column name or number>)

    If the data is a custom object:

    TextBox1.Text = DirectCast(ListBox1.Items(0), CustomObject).PropertyName

  • All times are GMT -7. The time now is 10:31 PM.