问题描述
下面是在gridview中将焦点设置到特定单元格的代码,但它不起作用。
dtEmployeeDocumentDetails = objEmployeeMasterBusiness.GetAllEmployeeDocumentDetails();
DataGridViewCheckBoxColumn CHK =新DataGridViewCheckBoxColumn();
gvEmpDocDetails.Columns.Add(CHK);
chk.HeaderText =选择;
chk.Name =chkselect;
gvEmpDocDetails.AllowUserToAddRows = false;
gvEmpDocDetails.DataSource = dtEmployeeDocumentDetails;
DataGridViewButtonColumn BTN =新DataGridViewButtonColumn();
btn.Name = btnDeleteEmpDocument;
btn.HeaderText =删除;
gvEmpDocDetails.Columns.Add(btn);
gvEmpDocDetails.Columns [1]。可见= FALSE;
gvEmpDocDetails.Columns [4]。可见= FALSE;
gvEmpDocDetails.Columns [ 5]。可见= FALSE;
gvEmpDocDetails.Columns [6]。可见= FALSE;
gvEmpDocDetails.Columns [8]。可见= FALSE;
gvEmpDocDetails.Columns [12] .Visible = false;
gvEmpDocDetails.Rows [2] .Cells [0] .Selected = true;
你能告诉我如何将焦点设置到单元格,以便在单元格单击事件中编写的代码在表单加载时工作正常。
谢谢。
Hi,
Below is the code to set focus to a particular cell in gridview, but its not working.
dtEmployeeDocumentDetails = objEmployeeMasterBusiness.GetAllEmployeeDocumentDetails();
DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn();
gvEmpDocDetails.Columns.Add(chk);
chk.HeaderText = "Select";
chk.Name = "chkselect";
gvEmpDocDetails.AllowUserToAddRows = false;
gvEmpDocDetails.DataSource = dtEmployeeDocumentDetails;
DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
btn.Name = "btnDeleteEmpDocument";
btn.HeaderText = "Delete";
gvEmpDocDetails.Columns.Add(btn);
gvEmpDocDetails.Columns[1].Visible = false;
gvEmpDocDetails.Columns[4].Visible = false;
gvEmpDocDetails.Columns[5].Visible = false;
gvEmpDocDetails.Columns[6].Visible = false;
gvEmpDocDetails.Columns[8].Visible = false;
gvEmpDocDetails.Columns[12].Visible = false;
gvEmpDocDetails.Rows[2].Cells[0].Selected = true;
Can you please let me know how to set focus to a cell so that the code written in my cell click event works fine when formloads.
Thanks.
这篇关于如何在Datagridview中将焦点设置到特定单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!