user485553
user485553

Reputation: 301

c# listBox DisplayMember

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 = ??????????

Upvotes: 1

Views: 6610

Answers (2)

Sherif Hamdy
Sherif Hamdy

Reputation: 593

This will work with you
textbox3.Text = listBox1.GetItemText(listBox1.SelectedItem);

Upvotes: 1

Henk Holterman
Henk Holterman

Reputation: 273419

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]

Upvotes: 2

Related Questions