views:

34

answers:

1

c# WinForms.Listbox.

listBox1.DataSource = ds.Tables[0].DefaultView;
listBox1.DisplayMember = "Question";
listBox1.ValueMember = "idQuestion";

//for ValueMember showing...   
textBox2.Text = listBox1.SelectedValue.ToString();

//What I must use for DisplayMember showing?  
textbox3.Text = ??????????
A: 

That may not be so easy with untyped tables. A Combobox has a Text property, for the listbox:

 textbox3.Text = listBox1.SelectedItem;

Gets you the 'item' but that probably is a DataRowView. You can cast it :
((DataRowViw) SelectedItem).Row[3]

Henk Holterman
//I used this construction.It's work fine, but does it correct? textBox3.Text = ((DataRowView)listBox1.SelectedItem).Row[1].ToString();
If it works it's OK. Also there is a deleted answer here suggesting Listbox.Text
Henk Holterman
Oh, tnx! textbox3.text = listbox1.text; It's really simple solution!!!