如前所述,我有一个数据网格 I NC# WPF,其中填充了 13 行信息。单击一行时,我可以选择该行,并且 SelectionChanged 事件触发,但第 10 行除外。单击此行甚至不会选择该行。如果我点击它上面或下面的行,事件就会触发,然后我可以使用键盘向上或向下箭头导航到第 10 行并选择它,然后触发事件,而不是通过鼠标单击,并且只有这一行。
行与其他行没有什么不同,并且是 100% 可重复的。那么为什么我不能用鼠标点击选择这一行呢?我应该检查什么?
<DataGrid x:Name="MyDataGrid" Width="826" Height="320" Margin="18,45,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" HorizontalContentAlignment="Center" ItemsSource="{Binding}" CanUserResizeColumns="False" IsReadOnly="True" CanUserResizeRows="False" SelectionMode="Single" AutoGenerateColumns="False" CanUserReorderColumns="False" SelectionChanged="dgBatches_SelectionChanged">
<DataGrid.Columns>
<DataGridTextColumn Header="Unit" Width="*" MinWidth="150" DisplayIndex="0" Binding="{Binding Path=Unit_Desc}" />
<DataGridTextColumn Header="Current Phase" Width="Auto" MinWidth="100" DisplayIndex="1" Binding="{Binding Path=Status_Phase}" />
<DataGridTextColumn Header="Batch" Width="Auto" MinWidth="80" DisplayIndex="2" Binding="{Binding Path=Batch_Number}" />
</DataGrid.Columns>
</DataGrid>
private void MyDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int selectedIndex = MyDataGrid.SelectedIndex;
}
private void PopulateMyDataGrid()
{
StoredProcedureExecutionResult sper = null;
List<Parameter> parameterList = new List<Parameter>();
parameterList.Add(CreateServiceParameter(1, "@ProductionDay", "9/15/2013");
sper = _databaseService.ExecuteProcedure(_databaseConnectionDor, "sp_PopulateGrid", parameterList);
if (null != sper.FirstTable)
{
DataTable batchTable = sper.FirstTable.DataTable.Copy();
MyDataGrid.DataContext = null;
MyDataGrid.DataContext = batchTable;
MyDataGrid.Items.Refresh();
}
}
谢谢