我们可以通过键盘上的TAB键或左右键来指定到DataGridView的某个单元格
上下左右的移动,这里我会触发一个事件:DataGridView1_CellLeave事件
当执行出错时再返回上一个单元格,不知道如何实现
用:this.dg_DataGridView1.Rows[e.RowIndex].Cells[3].Selected = true;
这条语句好像不起作用,谢谢高手指点!
上下左右的移动,这里我会触发一个事件:DataGridView1_CellLeave事件
当执行出错时再返回上一个单元格,不知道如何实现
用:this.dg_DataGridView1.Rows[e.RowIndex].Cells[3].Selected = true;
这条语句好像不起作用,谢谢高手指点!
解决方案 »
- 如何通过公网来访问内网中安装的网络摄像机
- devexpress gridControl控件请教
- C#中DataGridView中怎么设置可以选中多行?
- 关于深度复制的基础问题
- 到底是怎么回事呀??????我这3年在csdn上的问题怎么一下子给我删了!!!!!!!!!!!!!!!!!!!!!!111
- 关于实现 IList 接口的问题,请教高手!
- 这个马里兰 的时差怎么算的呀?
- 用NUnit进行单体测试的问题
- 如何读取JPG或GIF图片二进制格式?
- 求助!在Win2003上安装Visual Studio .NET2002出现问题
- 请教下 怎么把 开始菜单 开始图标 换 别的 (能换名字更好) 用代码实现
- 关于DataList下放置GrivdView控件
this.dataGridView1.[e.RowIndex].Cells[3].Selected = true;
this.dataGridView1.[e.RowIndex].Cells[3].Selected = true;
这个我试了还是不起作用呀dataGrid.CurrentCell = new DataGridCell(RowIndex, ColumnIndex);
这个怎么会报错呢继续关注
这个怎么会报错呢 报错?我用的是2005
错误贴出来
我是这样写的:
this.dg_Trans.CurrentCell = new DataGridCell(e.RowIndex, 3);
编译里出错:
错误:无法将类型“System.Windows.Forms.DataGridCell”隐式转换为“System.Windows.Forms.DataGridViewCell”
但VS2005下的DataGridView在new 时找不到:DataGridViewCell怎么实现呢,高手指点呀,谢谢
this.dataGridView1.CurrentCell = this.dataGridView1[1, 0];
2\this.dataGridView1.CurrentCell = this.dataGridView1[1, 0];
this.dataGridView1.BeginEdit(true);dataGridView1[1, 0] = dataGridView1[ColumnIndex, RowIndex],这个和习惯不一样
第二种方法不能放在form_onload里
我把我所有的代码贴出来:
private void dg_Trans_CellLeave(object sender, DataGridViewCellEventArgs e)
{
try
{
this.dg_Trans.EndEdit();
if (e.RowIndex == -1) return;
if (e.RowIndex < 0 || e.ColumnIndex < 0) return;
if (e.ColumnIndex != 3)
{
DataSet dsItem = new DataSet();
DataAccess.DAFittings Fitting = new DataAccess.DAFittings();
if (this.dg_Trans.Rows[e.RowIndex].Cells[3].Value != null)
{
dsItem = Fitting.GetMaterial(this.dg_Trans.Rows[e.RowIndex].Cells[3].Value.ToString());
if (dsItem.Tables[0].Rows.Count == 1)
{
this.dg_Trans.Rows[e.RowIndex].Cells[2].Value = dsItem.Tables[0].Rows[0][0].ToString();
this.dg_Trans.Rows[e.RowIndex].Cells[4].Value = dsItem.Tables[0].Rows[0][2].ToString();
}
else if (dsItem.Tables[0].Rows.Count == 0)
{
MessageBox.Show("提示:物料代码不存在,请从新输入", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
//this.dg_Trans.ClearSelection();
//this.dg_Trans.Rows[e.RowIndex].Cells[3].Selected = true;//光标返回到错语代码列
this.dg_Trans.EditMode = DataGridViewEditMode.EditOnEnter;
this.dg_Trans[e.RowIndex, 3] = this.dg_Trans[e.RowIndex, e.ColumnIndex-1];
//this.dg_Trans.CurrentCell = this.dg_Trans[e.RowIndex, 3];
//this.dg_Trans.BeginEdit(true);
}
}
}
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
------------------------------------------------------------------------------
是用TAB键来实现,最好是能用ENTER键来实现像TAB键一样的效果
这里会去做检查,如果物料不存在即提示,确认后返回到刚才有问题的那个单元格!
就是当执行下面的提示信息时,将光标返回到DataGridView中指定的单元格中
MessageBox.Show("提示:物料代码不存在,请从新输入", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
话又说回来,楼主如果为了达到这个效果要花很多时间的话我认为是不划算的!我当时的做法就是在信息框弹出后让单元格为选中状态!
this.dataGridView1.BeginEdit(true);