选择新添加的行 - DataGridView 和 BindingSource [英] Select newly added Row - DataGridView and BindingSource

查看:40
本文介绍了选择新添加的行 - DataGridView 和 BindingSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向绑定到 DataGridView 的 BindingSource 添加一个新行

I'm adding a new Row to a BindingSource that is Bound to a DataGridView

source.AddNew();

此后,使用 BindingSource 获取新添加的行,并在排序时返回 DataGridView 中的下一行.

After this, use BindingSource to get the newly added row is return the next row in the DataGridView when its sorted.

ROW "A"
ROW "B" <- myBindingSource.AddNew();
ROW "C"

myBindingSource.Current 给出 ROW "C".(它成为DataGridView中的选定行)

myBindingSource.Current gives ROW "C". (it became the selected row in the DataGridView)

我需要这个,因为我只想更新新添加的行

I need this because I want to update just the newly added row

            DataRowView drv = (DataRowView)myBindingSource.Current;
            myTableAdapter.Update(drv.Row);

而不是整个表格.

            myTableAdapter.Update(myDataSet.myTable);

而且,我想在插入后在 DataGridView 中选择这个新添加的行.

and also, I would like to have this newly added line selected in the DataGridView after insertion.

有可能吗?

推荐答案

不知道这是最好的解决方案,但例如看起来比迭代更好.

Dont know id its the best solution but for instance looks better than iterate.

        DataRowView drv = (DataRowView)source.AddNew();
        grupoTableAdapter.Update(drv.Row);
        grupoBindingSource.Position = grupoBindingSource.Find("ID", drv.Row.ItemArray[0]);

这篇关于选择新添加的行 - DataGridView 和 BindingSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆