在搜索中按下"框"键时选中网格复选框。网格不应该影响按键的显示搜索面板WPF模式!XAML 代码
<dxg:TableView Name="view" ShowTotalSummary="False" AlternateRowBackground="#FFE5EEF7" AlternationCount="2"
ShowSearchPanelMode="Always"
ShowSearchPanelFindButton="True"
SearchPanelFindMode="FindClick"
ShowSearchPanelCloseButton="True"
ShowGroupPanel="False" AllowColumnMoving="False"
AutoWidth="True" BestFitArea="All" DetailHeaderContent="True" ShowIndicator="False"
BestFitMode="AllRows" AllowEditing="True" >
C# 代码
private void dgv_Details_KeyDown(object sender, KeyEventArgs e)
{
try
{
int RowInd = Convert.ToInt32(dgv_Details.GetRowVisibleIndexByHandle(view.FocusedRowData.RowHandle.Value).ToString());
{
if (e.Key == Key.Enter)
{
if (ShowSearchPanelMode.Always.ToString() != "")
{
int RowIndex = Convert.ToInt32(dgv_Details.GetRowVisibleIndexByHandle(view.FocusedRowData.RowHandle.Value).ToString());
string itmId = dgv_Details.GetCellValue(RowIndex, "Item Code").ToString();
string check_ = "false";
itmId = dgv_Details.GetCellValue(RowIndex, "Item Code").ToString();
check_ = dgv_Details.GetCellValue(RowIndex, "IsSelect").ToString();
if (check_ == "false" || check_ == "False")
{
check_ = "true";
}
else
{
check_ = "false";
}
IEnumerable<DataRow> rows = dt.Rows.Cast<DataRow>().Where(r => r["itmId"].ToString() == itmId);
rows.ToList().ForEach(r => r.SetField("IsSelect", check_));
dt.AcceptChanges();
dgv_Details.ItemsSource = null;
dgv_Details.ItemsSource = dt;
dgv_Details.RefreshData();
}
dgv_Details.SetFocusedRowCellValue(ShowSearchPanelMode.Default.ToString(), RowInd);
}
}
}
catch (Exception exc)
{
DXMessageBox.Show(exc.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
我不太明白你想做什么,但在你的评论中你说
当焦点在我只想选中/取消选中复选框的行上时 回车键
关于这个问题,我可以给你的最简单的解决方案是:
private void dgvw_KeyDown()
if (e.Key == Key.Return)
{
dgvw.NotifyCurrentCellDirty(true);
dgvw.NotifyCurrentCellDirty(false);
}}
///Add this if required
dgvw.CommitEdit(DataGridViewDataErrorContexts.Commit);
希望这对:)有所帮助