Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listbox, textbox bind

Status
Not open for further replies.

ludmann

Programmer
Apr 14, 2004
49
GB
Can someone please tell me how to bind the listBox to a textbox?
In my code below, I have a listBox1, which is bound to a data table and displays a list of last names. I bound the selected value to email address, just because this is the primary key in the table.

Below the listbox, I have a textbox, which supposed to display all other fields in the row, that is selected in the listBox. I thought if I could get the datatable to return the id for the row, I could entered that in the text box section like, dt_shared.Rows[returnedid].ToString()

Is there a default id for a datarow in a datatable, and if yes how can I get it? And how can I then bind the listbox to the textbox?

If not how can I bind the listbox to the textbox?

listBox1.DataSource = dt_shared;
listBox1.DisplayMember = "LastName";
listBox1.ValueMember = "Email1Address";
listBox1.DataBindings.Add("SelectedValue",dt_shared,"Email1Address");


String str = "";

for(int i=0; i< dt_shared.Columns.Count; i++)
{
if(dt_shared.Rows[?].ToString() != null)
{
str = str + dt_shared.Rows[?].ToString() + "\r\n";
}

}

textBox1.Text = str;

Thank you

Marika
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top