在我的表单应用程序中,有一个(buttonNEW
)选择NewIndexRow
的DataGridView
,我想用此按钮更改datagridview的索引。以编程方式选择一行DataGridView
private void buttonNew_Click(object sender, EventArgs e)
{
if (dataGridView.CurrentRow.Index!=dataGridView.NewRowIndex)
{
dataGridView.ClearSelection();
dataGridView.Rows[dataGridView.NewRowIndex].Selected = true;
label1.Text = dataGridView.CurrentRow.Index.ToString();
}
}
但点击按钮后,DataGridView
索引不会改变。 问题是什么?
你确定NewRowIndex有价值? –
NewRowIndex为空行。我想用户点击buttonNEW并选择最后一行输入数据 – user1837982