WPF ComboBox using Llinq
-
Hi , I plaved a combobox and a listbox in a .xaml page. I used LINQ to fill combobox. I want the selected value to be displayed in the textbox. But i am getting object and not the exact value.I used like this, var value=additem.selectedItem; text1.text=value.ToString(); Pls help me! :(
Gomathi R
-
Hi , I plaved a combobox and a listbox in a .xaml page. I used LINQ to fill combobox. I want the selected value to be displayed in the textbox. But i am getting object and not the exact value.I used like this, var value=additem.selectedItem; text1.text=value.ToString(); Pls help me! :(
Gomathi R
GomathiR wrote:
text1.text=value.ToString();N/blockquote> Because you are doing a ToString() on the object. You would need to use the objects porperty value. e.g.
var value=additem.SelectedItem as YourObject; //YourObject is the object type which is the databound for each item
text1.text = value.PropertyInYourObject;You can do it in XAML itself also, databinding the Text property of text1. See if this works,
Text = ="{Binding ElementName=additem,Path=SelectedItem}"
-
GomathiR wrote:
text1.text=value.ToString();N/blockquote> Because you are doing a ToString() on the object. You would need to use the objects porperty value. e.g.
var value=additem.SelectedItem as YourObject; //YourObject is the object type which is the databound for each item
text1.text = value.PropertyInYourObject;You can do it in XAML itself also, databinding the Text property of text1. See if this works,
Text = ="{Binding ElementName=additem,Path=SelectedItem}"
Great answer!
-
GomathiR wrote:
text1.text=value.ToString();N/blockquote> Because you are doing a ToString() on the object. You would need to use the objects porperty value. e.g.
var value=additem.SelectedItem as YourObject; //YourObject is the object type which is the databound for each item
text1.text = value.PropertyInYourObject;You can do it in XAML itself also, databinding the Text property of text1. See if this works,
Text = ="{Binding ElementName=additem,Path=SelectedItem}"