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

查看:296
本文介绍了选择新添加的行 - 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给ROWC。 (它成为在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);



而不是整个表。

and not the entire table.

            myTableAdapter.Update(myDataSet.myTable);

和也,我想在插入后DataGridView中选择此新添加的行。

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

是否有可能以某种方式?

is it possible in some way?

推荐答案

不知道ID其。但对于例如最佳的解决方案看起来比更好的迭代

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天全站免登陆