How can I set a default value for the combobox to display? My combobox is filled with data from a list and I need it to display one of the values from that list. I have a product and the its category is displayed in that combobox and I need that when I
see the product details the category combobox value be set to the specific product category. I have tried using something like combo1.SelectedItem = "aaaa" but it doesn't work.
Well, I will try to explain the details of what I want to do and how I need to set that value for the combobox.
I have a Silverlight page that shows a datagrid of products and when I select one of the product another page Silverlight is opened and I am supposed to see the selected product details. I am sending the product id as a parameter to the new page and I get
all the information needed but for the Category combobox I don't want to get only the whole list of existing categories but when the page is loaded with all the data I want to see the value I choose for the combobox and not as unselected.
I have not used any DisplayMemberPath. I don't think it applies in my case. Specific code that could help I don't have. I just retrive the data needed from a wcf service using the product id and display all in textboxes and comboboxes.
giulia
Member
2 Points
8 Posts
Combobox set value
May 26, 2009 02:23 PM | LINK
How can I set a default value for the combobox to display? My combobox is filled with data from a list and I need it to display one of the values from that list. I have a product and the its category is displayed in that combobox and I need that when I see the product details the category combobox value be set to the specific product category. I have tried using something like combo1.SelectedItem = "aaaa" but it doesn't work.
Help?
varshavmane
Star
13229 Points
2753 Posts
Re: Combobox set value
May 26, 2009 03:08 PM | LINK
Have you set the DisplayMemberPath, if not then set it or else post your code.
Visit my Blog
giulia
Member
2 Points
8 Posts
Re: Combobox set value
May 26, 2009 04:28 PM | LINK
Well, I will try to explain the details of what I want to do and how I need to set that value for the combobox.
I have a Silverlight page that shows a datagrid of products and when I select one of the product another page Silverlight is opened and I am supposed to see the selected product details. I am sending the product id as a parameter to the new page and I get all the information needed but for the Category combobox I don't want to get only the whole list of existing categories but when the page is loaded with all the data I want to see the value I choose for the combobox and not as unselected.
I have not used any DisplayMemberPath. I don't think it applies in my case. Specific code that could help I don't have. I just retrive the data needed from a wcf service using the product id and display all in textboxes and comboboxes.
varshavmane
Star
13229 Points
2753 Posts
Re: Combobox set value
May 27, 2009 09:34 AM | LINK
You can first fill the combo and then set product i to it like this:
ddlProduct.SelectedIndex = productid;
or check this http://silverlight.net/forums/t/67956.aspx
Hope it helps you.
Visit my Blog
giulia
Member
2 Points
8 Posts
Re: Combobox set value
May 27, 2009 10:04 AM | LINK
Thank you! The index setting worked perfectly!