我有一张datagrid
的表单,其中包含表格中的记录列表。当用户选择一个记录来编辑其值时,我想返回到数据网格中的同一行(记录)并将其显示为选中状态。当然,数据网格应该显示新的(已编辑的)值。
EditButton
中的代码可以完成所有操作,但结果不是预期的结果。
private void zButtonEdit1_Click(object sender, EventArgs e)
{
// Store the rowIndex and columnIndex values
zButtonEdit1.rowIndex = dataGridView1.CurrentRow.Index;
zButtonEdit1.cellIndex = dataGridView1.CurrentCell.ColumnIndex;
// Store the Id of the current record
zButtonEdit1._id_ = Convert.ToInt16( dataGridView1["id_lice", zButtonEdit1.rowIndex].Value.ToString());
// Open the Editform with required data for that ID
Lice frmLice = new Lice(zButtonEdit1.UIB, zButtonEdit1._id_);
frmLice.ShowDialog();
// When editing is finished, refresh the grid with new values
refresh_controls();
//Set the current record pointer (or row pointer) to the record that was edited
this.dataGridView1.Rows[zButtonEdit1.rowIndex].Cells[zButtonEdit1.cellIndex].Selected = true;
}
这就是我得到的Datagrid on Form
很明显,我只更改了选择,但我不知道如何更改row
(记录)指针。
答案 0 :(得分:1)
根据要求:
设置当前选定的单元格:
SQL> drop user REIMPORT_TEST_SCHEMA cascade;
User dropped.
SQL> drop user TEST_EXP_OBJECTS cascade;
User dropped.
SQL> drop directory test_exp_dir;
Directory dropped.
的信息: https://msdn.microsoft.com/en-us/library/yc4fsbf5.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1