本人新手,问个菜鸟问题
在winform中使用dataGridView,在输入完某个cell的内容,离开时,想判断其内容,如不符合要求,要求光标重新强制回到此cell,说白了就是要让这个格子不填出符合要求的数据就让它无法跳到其它格子去我在CellLeave事件中写了:
dataGridView.CurrentCell = dataGridView.Rows[当前行].Cells[当前列];这条语句本身应该没有问题啊,可以让dataGridView任何一个格子获取焦点但是实际执行起来,为什么就无效了呢,感觉上鼠标点击或TAB后,焦点还是到另一个格子里去了,不会重新回到这个格子
在winform中使用dataGridView,在输入完某个cell的内容,离开时,想判断其内容,如不符合要求,要求光标重新强制回到此cell,说白了就是要让这个格子不填出符合要求的数据就让它无法跳到其它格子去我在CellLeave事件中写了:
dataGridView.CurrentCell = dataGridView.Rows[当前行].Cells[当前列];这条语句本身应该没有问题啊,可以让dataGridView任何一个格子获取焦点但是实际执行起来,为什么就无效了呢,感觉上鼠标点击或TAB后,焦点还是到另一个格子里去了,不会重新回到这个格子
解决方案 »
- winform里面的textbox的TextChanged事件不能回写
- C#读取XML
- 我在做五子棋时,如何保证每次单击后画上的棋子图案能够在其他程序遮盖后棋子不会消失?
- 建立treeView后,使用indexof(treenode)总是返回-1??
- 高分求<<ASP.NET信息管理系统开发实例导航>>这本书的光盘或者代码的下载地址
- 关于"由于线程退出或应用程序请求,已放弃 I/O 操作"错误的问题
- <authentication mode="?" />各种验证策略设置?
- 怎么在ListBox的DrawItem事件中画上PictureBox?此控件加载的图像为动画,即gif文件。
- 请教一个网络编程的问题
- 请问:用udp怎么发送广播
- 走到oCR.SetDataSource(ds) 运行结束,不抱错,看不到结果!
- 利用关键字搜索网站
在
dataGridView.CurrentCell = dataGridView.Rows[当前行].Cells[当前列];
加上下面的代码:
dg.EditMode = DataGridViewEditMode.EditProgrammatically;//.EditOnKeystroke;//.EditOnEnter;
dg.BeginEdit(true);
是不是这个不应该写在CellLeave事件中呢?那应该在哪处理呢?
{
if (dataGridView1.Columns[e.ColumnIndex].Name == "colName")
{
if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
dataGridView1.Rows[e.RowIndex].ErrorText = "此列值不能为空!";
e.Cancel = true;
}
}
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.Rows[e.RowIndex].ErrorText = String.Empty;
}