Hi everyone I'm new at wpf and I got some easy question:How can I get select item value from listbox? I wrote this code:
label1.Content = listBox1.SelectedItem.ToString();
and I get:System.Cindows.Control.ListBoxItem:Test1;
how can I get just Test1.
Thanks in advance!!
Wpf listbox select item problem
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
vkyadlapalli3 pointsPosted Sep 8, 2009, 11:29 PM EDT
mark dragan26 pointsPosted Sep 9, 2009, 12:58 PM EDT
label1.Content=item.ToString();
Hope this helps
anna2 pointsPosted Feb 9, 2010, 12:38 AM EST
Label x = listBox.SelectedItem as Label;
String y= sourcelbi.Content.ToString();
Martin Cook45 pointsPosted Feb 10, 2010, 1:14 AM EST
You might want to look up Element Binding which allows you to achieve this with no code behind, something along these lines: -
<ListBox x:Name="ListBox1" ItemsSource="{Binding} SelectedValuePath="IDOrSomething" DisplayMemberPath="PropertyYouWantToDisplay" /> <Label Content="{Binding ElementName=ListBox1, Path=SelectedValue}" />1 short reply
mark dragan26 pointsPosted Aug 22, 2009, 8:34 AM EDT