DataGridView 单元格获得焦点并且是编辑状态 怎么样让 DataGridView 单元格获得焦点并且是编辑状态,比如现在焦点在第一行的第二列,当单击第一行的第三列时,让第一行第一列获得焦点,并且是编辑状态 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 编辑列?还是行?gridView好像是编辑行吧 有具体的代码吗? 我是想实现excel的功能。在一个新行获得编辑状态,如果当前行的第一列没有值 就把编辑状态跳到当前行的第一列,我试了好像只能让第一列选中而不能处于编辑状态 LZ试试将DGV的EditMode设置成EditOnEnter,再在SelectionChanged事件里添加以下代码:if (DGV.SelectedCells.Count != 0){ if (DGV.SelectedCells[0].ColumnIndex == 2) { DGV.CurrentCell = DGV.Rows[DGV.SelectedCells[0].RowIndex].Cells[0]; }} private void initdata() { DataTable tbl = new DataTable(); tbl.Columns.Add("id", typeof(string)); tbl.Columns.Add("name", typeof(string)); for (int i = 0; i < 3; i++) { DataRow r = tbl.NewRow(); r[0] = ""; r[1] = i.ToString(); tbl.Rows.Add(r); } this.dataGridView1.DataSource = tbl.DefaultView; this.dataGridView1.CellEnter += new DataGridViewCellEventHandler(dataGridView1_CellEnter); } void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == 0 && e.ColumnIndex == 0) { if (this.dataGridView1.CurrentCell.Value.ToString() == "") { this.dataGridView1.BeginEdit(false); } } } 你有没有将DataGridView的EditMode属性设置成EditOnEnter呢? 已经设置了,按你的代码只能让第一列处于选中的状态而不是编辑状态。我也是了后面加beginEdit()方法但是还不行,结果是第一列选中,而以前选的列处于编辑,我也正奇怪着呢! 你的DGV或者对应的列是否是设置为只读的呢??如果不是的话就应该会没有问题的,因为设置为EditOnEnter后就没有的区分开选中状态与编辑状态了,只要焦点落在cell上就自动变成编辑状态了,如果设置为只读的话,就只有选中状态没有编辑状态了 DGV.CurrentCell =EditOnEnter=oneditcontrolshowing写代码都用上,试试(我没试过。) 求教如何反编译一个用.NET开发的EXE文件 C#十进制转16进制 Lucene搜索 反编译工具reflector的问题 html转PDF的类库,要支持table CheckedListBox数据绑定后不能显示 被绑定的数据(在线等,急) treeview 使用的问题 求助:textbox控件赋值的问题.在线等,谢谢. TreeView问题(WEBFORM) 初学者的困惑:sql 语句中参数传递问题,谢谢!一个极简单的问题! 为什么不能跳转页面! 在Form1点击一个(button)按纽,出现另一个窗体Form2
在一个新行获得编辑状态,如果当前行的第一列没有值 就把编辑状态跳到当前行的第一列,我试了好像只能让第一列选中而不能处于编辑状态
if (DGV.SelectedCells.Count != 0)
{
if (DGV.SelectedCells[0].ColumnIndex == 2)
{
DGV.CurrentCell = DGV.Rows[DGV.SelectedCells[0].RowIndex].Cells[0];
}
}
private void initdata()
{
DataTable tbl = new DataTable();
tbl.Columns.Add("id", typeof(string));
tbl.Columns.Add("name", typeof(string));
for (int i = 0; i < 3; i++)
{
DataRow r = tbl.NewRow();
r[0] = "";
r[1] = i.ToString();
tbl.Rows.Add(r);
}
this.dataGridView1.DataSource = tbl.DefaultView;
this.dataGridView1.CellEnter += new DataGridViewCellEventHandler(dataGridView1_CellEnter);
} void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == 0 && e.ColumnIndex == 0)
{
if (this.dataGridView1.CurrentCell.Value.ToString() == "")
{
this.dataGridView1.BeginEdit(false);
}
}
}
EditOnEnter=
oneditcontrolshowing写代码
都用上,试试(我没试过。)