I have a ComboBox that need to be binded to a certain Dictionary value. This is because I could have N tabs (each with an ID) on my app and in each tab I have a ComboBox. Right now I have:
ComboBox cb = new ComboBox()
{
Width = 200,
Height = 26,
Name = "cbRelatorio" + id
};
Binding bindingCb = new Binding();
bindingCb.Source = DataContext;
bindingCb.Path = new PropertyPath("ReportSheet[" + id + "]");
bindingCb.Mode = BindingMode.TwoWay;
bindingCb.ValidatesOnDataErrors = true;
cb.SetBinding(ComboBox.SelectedValueProperty, bindingCb);
sheetPanel.Children.Add(cb);
That "id" is received by the method and is regarding the ID I talked in the beginning. For example, on ReportSheet[1]
I'll have the selected value of the combobox on the first tab.
If I select the value, on the combobox this is saved well on the dictionary, but if this respective value is already set, don't show in the combobox on created. Am I missing something here?
For example, If I have a combobox with:
- Option 1
- Option 2
- Option 3
And select one of them is selected well to my ReportSheet[1].
What I want is to define a default value, lets say Option 2:
combobox.itemssource = datacontext;
ReportSheet[1].SelectedValue = "Option 2";
When the combobox is loaded for the first is empty, doesn't have selected the "Option 2".