none
Vb.net How to get a value of a selecteditem in a listbox? RRS feed

  • Question

  • My code looks something like this:

            TextBox2.Text = ListBox2.SelectedItem
            Label2.Text = "My.settings." + TextBox2.Text
            Label4.Text = Label2.Text + ".ToString"
            If TextBox2.Text = ListBox2.SelectedItem Then
                TextBox3.Text = My.Settings.ToString
            End If


    in the textbox2 i want the value of my.settings.Listbox

    and if i make a textbox that gets the name i cannot do it like this:

            TextBox2.Text = ListBox2.SelectedItem
            Label2.Text = "My.settings." + TextBox2.Text
            Label4.Text = Label2.Text + ".ToString"
            If TextBox2.Text = ListBox2.SelectedItem Then
                TextBox3.Text = My.Settings. + label2.text .ToString
            End If

    but how can i make it like:

    when i click an item it will get the items value in the textbox.

    but i do not want it like this

    if listbox1.selecteditem = "Listbox" then
    textbox3.text = my.settings.listbox.tostring
    textbox2.text = listbox1.selecteditem
    end if

    Tuesday, July 2, 2013 8:22 PM

All replies

  • Hi,

    This post is more of a .Net's post. However, what I understand from your question, just create an event for your listbox "OnSelectedIndexChanged" and get the selected listitem value into your textbox. Secondly, to get the value you need to use Value property of listbox, like this listbox1.SelectedItem.Value.

    protected void listbox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        textbox2.text = listbox1.SelectedItem.Value;
    }

    If this is not what you were looking for, kindly elaborate your question.

    Thanks


    IN
    Thanks, Kashif


    • Edited by Kashif Nizam Wednesday, July 3, 2013 11:09 AM code block added
    Wednesday, July 3, 2013 10:59 AM