i have a problem with the ValueMember. I saved all my Items in a ListBox with two members:
listBox1.ValueMember = "userId";
listBox1.DisplayMember = "userName";
Now i create a loop to add my Obj into the list:
foreach (var tempItem in listWithObjs)
{
MyItem testItem = new MyItem();
testItem.userID = tempitem;//userID and userName are Strings the content is not very important i think
testItem.userName = item.Split('\\').Last();
listBox1.Items.Add(testItem);
}
at least, I try to get the UserID when I double Click on an Item of my List:
private void listBox1_DoubleClick(object sender, EventArgs e)
{
var selected = listBox1.SelectedValue; //SelectedValue is null
label1.Text = Convert.ToString(selected);
}
and here is the problem SelectedValue is null.
i try to use SelectedItem but this just returns "MyItem", i try to get the complete object from the select but that dosent work.
How can I get the ValuedMember "UserID" to the String selected?
much thanks for the Answers :)