Hi

I have a DataGrid bound to a DataView, and when adding a new row to the view I want it to be the current/selected one
I've tried the followerin

DataRowView row = myView.AddRow()
row["Date"] = DateTime.Today

Re: Identifying a newly created row ? by v-kevy

v-kevy
Wed Feb 04 20:43:33 CST 2004

Thanks for Miha's quick response,

Hi Jorgen,

Thank you for posting in the community!

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you would like to select a row which
has just been created on the datagrid. If there is any misunderstanding,
please feel free to let me know.

Miha has provided us with a good suggestion. Besides, we can also use
CurrencyManager to achieve this. CurrencyManager class is used to manage a
list of Binding objects. We can also use it to add new rows to data source.
Here I've written a code snippet according to your needs.

DataView dv = (DataView)this.dataGrid1.DataSource;
CurrencyManager cm = (CurrencyManager)this.BindingContext[dv];
cm.AddNew();
DataRowView row = (DataRowView)cm.Current;
row["Date"] = DateTime.Today;
row.EndEdit();
this.dataGrid1.Select(cm.Position);

For more information about CurrencyManager, here is a link for your
reference:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemwindowsformscurrencymanagerclasstopic.asp

Does this answer your question? If anything is unclear, please feel free to
reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."