C# 在C中验证单元格并显示datagridview的引出序号工具提示#
我的表单中有一个datagridview,每次用户向某个单元格输入值时,我都希望对一行执行验证 我曾尝试使用RowValidating事件,但将e.Canel设置为true后出现了一些问题:C# 在C中验证单元格并显示datagridview的引出序号工具提示#,c#,winforms,validation,datagridview,tooltip,C#,Winforms,Validation,Datagridview,Tooltip,我的表单中有一个datagridview,每次用户向某个单元格输入值时,我都希望对一行执行验证 我曾尝试使用RowValidating事件,但将e.Canel设置为true后出现了一些问题: 用户只需单击同一行上的另一个单元格,或在键入单元格值后按TAB或ENTER键,即可退出编辑模式并编辑其他行 当e.Canel==true时,整个表单似乎被卡住了,这是一件好事。但是,如果用户试图关闭窗体(通过按下左角的“关闭”按钮),则只有窗口的外部边框消失,窗体中的其余控件保持“浮动”(仍被卡住) 所
- 用户只需单击同一行上的另一个单元格,或在键入单元格值后按TAB或ENTER键,即可退出编辑模式并编辑其他行
- 当e.Canel==true时,整个表单似乎被卡住了,这是一件好事。但是,如果用户试图关闭窗体(通过按下左角的“关闭”按钮),则只有窗口的外部边框消失,窗体中的其余控件保持“浮动”(仍被卡住)
提前谢谢 为DataGridView控件的CellValidating和CellEndEdit事件实现处理程序
private void dataGridView1_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
// Validate the CompanyName entry by disallowing empty strings.
if (dataGridView1.Columns[e.ColumnIndex].Name == "CompanyName")
{
if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
dataGridView1.Rows[e.RowIndex].ErrorText =
"Company Name must not be empty";
e.Cancel = true;
}
}
}
void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
// Clear the row error in case the user presses ESC.
dataGridView1.Rows[e.RowIndex].ErrorText = String.Empty;
}