本人做的是vb.net 大伙给c#的代码也可以
就是 winform上有 2个一样的 gridview
一共5列 前面2列是不可以输入的 后面3列是可以输入的
当 按下 enter 的时候 焦点在后面3列移动
从左到右 从上到下 也就是从 第一gridview的第一行第三列开
一直移动到第二gridview的最后一行最后一列 如此循环
还有个问题请教下
比如有个gridview有6行 最后一行跟最后第二行取得的
gridview.CurrentCell.RowIndex 怎么都是5?
而且gridview.CurrentCell.RowIndex从1开始的有点奇怪
gridview.CurrentCell.ColumnIndex 从0开始都正确的
就是 winform上有 2个一样的 gridview
一共5列 前面2列是不可以输入的 后面3列是可以输入的
当 按下 enter 的时候 焦点在后面3列移动
从左到右 从上到下 也就是从 第一gridview的第一行第三列开
一直移动到第二gridview的最后一行最后一列 如此循环
还有个问题请教下
比如有个gridview有6行 最后一行跟最后第二行取得的
gridview.CurrentCell.RowIndex 怎么都是5?
而且gridview.CurrentCell.RowIndex从1开始的有点奇怪
gridview.CurrentCell.ColumnIndex 从0开始都正确的
解决方案 »
- c#搜索txt文件
- 用HTTP传输一张图片,求大佬解答
- 求高人给一个C#正则表达式!关于从字符串中提取多个图片文件路径
- listview控件一个奇怪问题!!!!!!!!!!!!!求解
- 独立局域网(不连internet)中的ip地址是如何给出的,是任意的吗?独立局域网中的IP地址是否与internet的IP地址无关,并且可以重复任意选择?
- 如何让多个类实例变量共用一段执行代码?
- C#中如何把字符串转换为二进制?
- winform绑定数据窗口, 关联表添加新记录的问题.
- 保存字体颜色状态变化
- 不得了,有人在灌水乐园发贴子攻击版主saucer(思归),快来看啊
- 如何将当前鼠标弄成透明的,或者让当前鼠标加载一个透明的资源,类似VC++那样
- 错误提示:SelectCommand.属性尚未初始化
{
if (e.KeyCode == Keys.Tab)
{
SendKeys.Send("{Enter}");
e.Handled = true;
}
}
问题2
你绑定的数据源有问题或者是DataGridView某些设置有问题把
你的这个方法 之前也用过
焦点会5个列都跑的
焦点也能上去的
你代码是加上判断,如果此列是只读,那么就再次发送SendKeys.Send("{Enter}");
你看这样的思路可不可以
当你按enter键就做个判断,如果列索引小于4,就把焦点后移一个cell,否则移到下一行的列索引2
{
if (e.KeyCode == Keys.Tab)
{
SendKeys.Send("{Enter}");
e.Handled = true;
}
}
好像 完全不行么 你试过吗
{
SendKeys.Send("{Tab}");
e.Handled = true;
}
但是 又要跳过 前面2个不能输入的列
{
SendKeys.Send("{Tab}");
e.Handled = true;
}
你的方法跟我下面方法是一样 我重写了 就是tab的效果 但要跳过
前面2列不能输入的 还是没有解决
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, _
ByVal keyData As System.Windows.Forms.Keys) As Boolean Select Case keyData
Case Keys.Enter
SendKeys.Send("{Tab}")
Return True
End Select MyBase.ProcessCmdKey(msg, keyData) Return False End Function
Private Sub gl001_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles gl001.KeyPress If gl001.CurrentCell.ColumnIndex < 4 Then
gl001.CurrentCell = gl001(gl001.CurrentCell.ColumnIndex + 1, gl001.CurrentCell.RowIndex - 1)
Return
ElseIf gl001.CurrentCell.RowIndex < gl001.RowCount And gl001.CurrentCell.ColumnIndex = 4 Then
gl001.CurrentCell = gl001(2, gl001.CurrentCell.RowIndex)
Return
ElseIf gl001.CurrentCell.RowIndex = gl001.RowCount - 1 And gl001.CurrentCell.ColumnIndex = 2 Then
gl001.CurrentCell = gl001(2, 1)
Return
End If End Sub
还有这个方法 但是gridview.CurrentCell.RowIndex这个最后行出问题了
我测试没有问题.
private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
if (dataGridView1.Columns[this.dataGridView1.CurrentCell.ColumnIndex].ReadOnly)
{
SendKeys.Send("{Tab}");
e.Handled = true;
}
} private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
if (dataGridView1.Columns[this.dataGridView1.CurrentCell.ColumnIndex].ReadOnly)
{
SendKeys.Send("{Tab}");
e.Handled = true;
}
else
{
SendKeys.Send("{Tab}");
e.Handled = true;
}
}
}
{
if (dataGridView1.Columns[this.dataGridView1.CurrentCell.ColumnIndex].ReadOnly)
{
SendKeys.Send("{Tab}");
e.Handled = true;
}
} private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
SendKeys.Send("{Tab}");
e.Handled = true;
}
}
2 个 都写上这2个事件的话
还有个小问题 请教下
就是第一个运行完毕
会跳到第二个GridView 的 第一行的第1个cell
然后按enter 直接跳到 第一行的第4个cell(跳过了一个正确的cell)
才开始就运行正常
第一行不是只读的cell 也就是第一行第3列
我这里取GridView的CurrentCell的坐标一直有点问题
能再帮忙看看嘛
在你的第二个datagridview里也加上上面的两个事件及代码
因为你第一个datagridview结束之后 没有指定跳到下个datagridview的具体位置
所以默认焦点到了 第一个cell
才写代码 把焦点设置到下个datagridview的具体位置
如datagridview1为3,那么第二个为4第二:在你的第二个datagridview获得焦点事件里写上判断代码.
第一个datagridview的KeyPress的事件里面 如果认为这个是
最后一个cell 就代码设置使焦点跳到
第二个datagridview的可输入的第一个cell这是我的思路了 关键问题还是我这里第一个datagridview取cell坐标有问题
所以想请你看一下
请问这个获得焦点的事件在哪里?
就是控件为窗体的活动控件时. private void dataGridView1_Enter(object sender, EventArgs e)
{ }
你的思路要清晰,答的我都有点晕头转向了.