如何选择并滚动到新行中的DataGridView? [英] How to select and scroll to new Row in Datagridview?
问题描述
我有一个绑定到一个数据库表一个DataGridView。 在DataGridView是不可编辑的,也有一些文本字段,其中数据可以被编辑,被控制的按钮。 我有以下code进行NEWROW按钮:
I have a DataGridView bound to a DB Table. The DataGridView is not editable, there are some text fields where the data can be edited, which is controlled with buttons. I have a NewRow Button with the following code:
dataGridView1.AllowUserToAddRows = true;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Selected)
{ row.Selected = false; }
}
dataGridView1.Rows[dataGridView1.NewRowIndex].Selected = true;
笏我需要的是:
Wat I need is:
- 在DataGridView应滚动到底部(其中NEWROW为)
- 的NEWROW应集中,使得文本框显示新的(空)行(内容)
我已经试过:
bindSourceGS.Position = dataGridView1.NewRowIndex;
但是,这并不选择在DataGridView的NEWROW。 我想用在DataGridView的NEWROW因为当用户presses取消按钮,我没有删除该行的数据集和datagridview.Rows [I]有IsNewRow属性。
but that doesn't select the datagridview's newRow. I want to use the datagridview's newRow because when user presses cancel button I don't have to delete the row in the Dataset and the datagridview.Rows[i] has a IsNewRow Property.
推荐答案
如果它的的Winform 的,那么你可以使用这个
If its Winform then you can use this
dataGridView1.FirstDisplayedScrollingRowIndex
和设置 datagridview.CurrentCell
来新行单元格地址。
and set the datagridview.CurrentCell
to your new row cell address.
希望这有助于
这篇关于如何选择并滚动到新行中的DataGridView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!