Simple Codeplex ComboBox problem - preselect/preset ComboBox selectedValue or text

Jul 8, 2010 at 3:30 AM

Hello

I'm using CodePlex WPF ComboBox and is having trouble pre-select item

From code behind, I bind the combo box to a DataTable with two columns:
...
SomeTableSrc = new DataTable("SomeData");
SomeTableSrc.Columns.Add("Data", typeof(string));
SomeTableSrc.Columns.Add("IsSelected", typeof(bool));
lstSomeData.DataContext = SomeTableSrc.DefaultView;

Xaml:
<Style TargetType="{x:Type ComboBoxItem}">
</Style>

The above will select relevant "ComboBoxItem" (and it works fine, if you click on ComboBox, as menu expands you can see desired items actually get selected), *** BUT *** "SelectedValue" or "Text" of "ComboBox" (not items) remains blank - and setting these "ComboBox" attributes directly just don't work.
// Don't work, "ComboBox" text remains blank
lstSomeData.SelectedValue = "ABC";

// Don't work, "ComboBox" text remains blank
lstSomeData.Text = "ABC";

And I've already tried (PreSelectedData = code behind attrib hardcoded to return string "ABC"):
<ComboBox.ItemContainerStyle ItemsSource={Binding} Text="{Binding PreSelectedData}" SelectedValue="{Binding PreSelectedData}">
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="IsSelected" Value="{Binding Path=IsSelected}" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>

Or even outright hardcode,
<ComboBox.ItemContainerStyle ItemsSource={Binding} Text="ABC" SelectedValue="ABC">
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="IsSelected" Value="{Binding Path=IsSelected}" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>

No luck!