Search code examples
c#databasetextboxlistbox

Fill the whole row of listbox selected items in form controls


I have a text box, and I have written code on a textbox textchange event so that when I type any text, related text is retrieved from my database and shown in a listbox.

I want to be able to click on any name in the list box, and make the whole row related to that name show on form controls.


Solution

  • If I understand you well, you would like to copy selected text (from a selected row in listBox) to textBox. You can easily do like it:

      private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
      {
          textBox1.Text = listBox1.SelectedItem.ToString();
      }
    

    Mitja