Silverlight DataGrid TemplateColumn adding problem with ComboBox
I am in little trouble with this problem. I have made a DataGrid and it have DataTemplate Columns. here is the XAML for that
<data:DataGrid x:Name="PortsGrid" Height="124" Margin="23,0,17,2" VerticalAlignment="Bottom" ItemsSource="{Binding PortsGridData, Mode=TwoWay}" AutoGenerateColumns="False" SelectionMode="Single">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="Specific port/Range" CanUserResize="False" Width="130" Binding="{Binding Port}"/>
<data:DataGridTemplateColumn Header="Timeout" CanUserResize="False" Width="130" >
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="TimeoutComboBox" IsEditable="True" SelectedIndex="{Binding TimeoutIndex}">
<开发者_如何学JAVA;ComboBoxItem Content="First Value" Tag="-1"/>
<ComboBoxItem Content="Second Value" Tag="0"/>
</ComboBox>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
<data:DataGridTemplateColumn Header="Priority" CanUserResize="False" Width="120">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="PriorityComboBox" SelectedIndex="{Binding PriorityIndex}">
<ComboBoxItem Content="Low" Tag="0"/>
<ComboBoxItem Content="Prio1" Tag="1"/>
<ComboBoxItem Content="Prio2" Tag="2"/>
<ComboBoxItem Content="Prio3" Tag="3"/>
<ComboBoxItem Content="Prio4" Tag="4"/>
</ComboBox>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
<data:DataGridTemplateColumn Header="Compression" CanUserResize="False" Width="105">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="CompressionComboBox" SelectedIndex="{Binding CompressionIndex}">
<ComboBoxItem Content="On" Tag="1"/>
<ComboBoxItem Content="Off" Tag="0"/>
</ComboBox>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
<data:DataGridTemplateColumn Header="Protocol" CanUserResize="False" Width="100">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="ProtocolComboBox" SelectedIndex="{Binding ProtocolIndex}">
<ComboBoxItem Content="Proto1"/>
<ComboBoxItem Content="Proto2"/>
</ComboBox>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
</data:DataGrid.Columns>
</data:DataGrid>
this data grid is binded with a ObservableCollection
, If I add a row in this datagrid by adding an element in ObservableCollection comboboxes are added with their default value, i.e. no value selected. Now if I change the combo boxes selection and then remove this row, and add this row again, the comboboxes will be added with their previous states, not the default state.. why is this happening.. It might be that DataGrid is storing the Combobox states for better performance, but how to clear those values?
精彩评论