我有一个 DataGrid,它们的行更新得非常快。每行都有一个右键单击事件,如果单击,则应将所选行添加到另一个数据网格中。问题是,当用户选择一行以便添加到另一个列表时,由于更新了所选行,他无法添加,因此用户应该一次又一次地选择该行。我的代码是这样的
<DataGrid SelectionMode="Single" CanUserAddRows="False"CanUserDeleteRows="False" >
<DataGrid.Columns>
<DataGridTextColumn Header="Data1" Binding="{Binding Path=Data1}"></DataGridTextColumn>
<DataGridTextColumn Header="Data2" Binding="{Binding Path=Data2}"></DataGridTextColumn>
<DataGridTextColumn Header="Data3" Binding="{Binding Path=Data3}"></DataGridTextColumn>
<DataGridTextColumn Header="Data4" Binding="{Binding Path=Data4}"></DataGridTextColumn>
<DataGridTextColumn Header="Data5" Binding="{Binding Path=Data5}"></DataGridTextColumn>
<DataGridTextColumn Header="Data6" Binding="{Binding Path=Data6}"></DataGridTextColumn>
</DataGrid.Columns>
<DataGrid.ContextMenu>
<ContextMenu HorizontalContentAlignment="Right" FlowDirection="RightToLeft">
<MenuItem Name="addToBlackListMnuBtn" Header="Add to Black List" Click="addToBlackListMnuBtn_Click" FontWeight="Black"/>
<MenuItem Name="addtoReportedListMnuBtn" Header="Add to Reported List" Click="addtoReportedListMnuBtn_Click" FontWeight="Black"/>
</ContextMenu>
</DataGrid.ContextMenu>
</DataGrid>
当我想从 contexMenu 单击“addtoReportedListMnuBtn”时,我应该尝试几次来执行其事件。通常通过下面的代码显示消息框
private void addtoReportedListMnuBtn_Click(object sender, RoutedEventArgs e)//add to reported list
{
ObjClass en = (ObjClass)ActiveSignalDataGrid.SelectedItem;
if(en!=null)
{
ReportSignalsListQ.Data = en; // add to queue for adding
}else
{
MessageBox.Show("Please select again");
}
}
翻阅古今
蝴蝶刀刀
相关分类