ComboBox in DataGrid Issue with RC0
we will run into wierd issue, if we try to use ComboBox in DataGrid (Silverlight RC0). you can find more details in this forum post
I think this will be addressed before Silverlight 2.0 is released. Here is a temporary workaround
I got all the code from the forum post, ( so I am not including the code)
Here is a workaround
Create a class, similar to this and set IsDropDownProperty to true in the loaded event
public class MyComboBox : ComboBox
{
public MyComboBox()
{
DefaultStyleKey = typeof(ComboBox);
this.Loaded += new RoutedEventHandler(MyComboBox_Loaded);
}
{
public MyComboBox()
{
DefaultStyleKey = typeof(ComboBox);
this.Loaded += new RoutedEventHandler(MyComboBox_Loaded);
}
void MyComboBox_Loaded(object sender, RoutedEventArgs e)
{
IsDropDownOpen = true;
}
}
{
IsDropDownOpen = true;
}
}
After declaring the Namespace
xmlns:src=”clr-namespace:xxx;assembly=xxx”
use the combobox like this
<data:DataGridTemplateColumn Header=”City”>
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text=”{Binding City}” />
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
<data:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<src:MyComboBox SelectedItem=”{Binding City, Mode=TwoWay}”
ItemsSource=”{Binding CityList, Source={StaticResource cityProvider}}”
/>
</DataTemplate>
</data:DataGridTemplateColumn.CellEditingTemplate>
</data:DataGridTemplateColumn>
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text=”{Binding City}” />
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
<data:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<src:MyComboBox SelectedItem=”{Binding City, Mode=TwoWay}”
ItemsSource=”{Binding CityList, Source={StaticResource cityProvider}}”
/>
</DataTemplate>
</data:DataGridTemplateColumn.CellEditingTemplate>
</data:DataGridTemplateColumn>
[...] you try to open ComboBox, it display and then immediately closes. I posted about it here and Lee found a work around. Here is the work around. Use MyComboBox in place of ComboBox in above [...]
ComboBox in DataGrid - Manish Dalal's blog
September 29, 2008
[...] … sort of looks like the stagecoach coming in surrounded by a cloud of dust… pretty cool
ComboBox in DataGrid Issue with RC0 Amazingly enough, Lee took off today on the Combobox in DataGrid issue as well… and Lee has a [...]
Silverlight Cream for September 29, 2008 -- #382
October 3, 2008