将焦点设置到数据网格视图文本框列单元格 [英] Set focus to Data Grid View Text Box Column Cell
本文介绍了将焦点设置到数据网格视图文本框列单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我型datagridview的文本框列的gridview的,在以下的列有:
I have a gridview of type datagridview text box column, in that following columns are there:
SrNo | Description | HSNCode | Qty | Rate | Amount
我在我的程序自动生成量,但我要检查,如果用户输入到无率中输入数据,然后我想将焦点设置回费率字段在我的计划金额字段:
I am generating amount in my program automatically, but I want to check if the user has entered to amount field without entering data in "Rate" then I want to set focus back to the "Rate" field in my program:
我曾尝试下面的代码:
private void grdData_CellLeave(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 4)
{
if(grdData.Rows[e.RowIndex].Cells[4].Value== null)
{
grdData.CurrentCell = grdData.Rows[e.RowIndex].Cells[4];
}
}
}
但是代码不工作。结果
我应该怎么做将焦点切换到以前的是对数量?结果
请帮忙领域。
But the code is not working.
What should I do to switch focus to the field that is previous to the "Amount"?
Please help.
推荐答案
尝试:
private void grdData_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (e.ColumnIndex == 5)
{
if(grdData.Rows[e.RowIndex].Cells[3].Value.Equals(""))
{
grdData.ClearSelection();
grdData.Rows[e.RowIndex].Cells[3].Selected = true;
}
}
}
更新 - 测试,工作正常使用 cellclick
事件
private void grdData_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 5)
{
if(grdData.Rows[e.RowIndex].Cells[3].Value.Equals(""))
{
grdData.ClearSelection();
grdData.Rows[e.RowIndex].Cells[3].Selected = true;
}
}
}
这篇关于将焦点设置到数据网格视图文本框列单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文