How to find newly added row in sorted/filtered DataTable?

P

Piotr Olech

I add record to DataTable in DataSet. I have a grid attached to that DT. I
want the grid to position to the newly added record, even if the contents of
grit is sorted or filtered.
As I can understand, grid is based on DataView of DT (especially on
DefaultView)?
So all I need is to know what is the position of that new row in current DV.
I could then set:
((CurrencyManager) this.BindingContext[DS, DT.TableName]).Position =
PositionOfNewRow
That should be enough.
Am I right? Then how can I obtain PositionOfNewRow?
I can't use any method based on Primary key, because I try to write a base
class in which I don't know exact names of tables, fields, keys etc.
Any ideas?
Or, may be, there are better ways to get what I want?

Regards
 
M

Miha Markic

Hi Piotr,

DataGrid already offers a new row line at the bottom.
If you add row directly to datatable then it won't appear in DataView if it
doesn't meet the criteria.
If it does meet the criteria, you'll find its position by using
DataView.Find method.
 
P

Piotr Olech

Hi Miha,
Thanks for tryig to help me.
I know, that grid offers such functionality, but for some reasons I don't
want to allow editing on grid.
So I have to add row in code.
I understand the behaviour when a filter is applied. OK, there is nothing to
do with it.
But what about sorted grid (DataView)? I have "in hand" a DataRow when I
call DT.Add(DR). How to know the position in DataView the added record is
placed on?
As I mentioned, I can't use the Find method because in base class I don't
know the key fields...
Any other sugestions?
(I try to deal with ListChanged event of DataView, but would like, there was
simpler way...)

Regards

--
Piotr Olech
Remove "spam_off" while answering...

Miha Markic said:
Hi Piotr,

DataGrid already offers a new row line at the bottom.
If you add row directly to datatable then it won't appear in DataView if it
doesn't meet the criteria.
If it does meet the criteria, you'll find its position by using
DataView.Find method.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Piotr Olech said:
I add record to DataTable in DataSet. I have a grid attached to that DT. I
want the grid to position to the newly added record, even if the
contents
of
grit is sorted or filtered.
As I can understand, grid is based on DataView of DT (especially on
DefaultView)?
So all I need is to know what is the position of that new row in current DV.
I could then set:
((CurrencyManager) this.BindingContext[DS, DT.TableName]).Position =
PositionOfNewRow
That should be enough.
Am I right? Then how can I obtain PositionOfNewRow?
I can't use any method based on Primary key, because I try to write a base
class in which I don't know exact names of tables, fields, keys etc.
Any ideas?
Or, may be, there are better ways to get what I want?

Regards
 
M

Miha Markic

Piotr Olech said:
Hi Miha,
Thanks for tryig to help me.
I know, that grid offers such functionality, but for some reasons I don't
want to allow editing on grid.
So I have to add row in code.
I understand the behaviour when a filter is applied. OK, there is nothing to
do with it.
But what about sorted grid (DataView)? I have "in hand" a DataRow when I
call DT.Add(DR). How to know the position in DataView the added record is
placed on?
As I mentioned, I can't use the Find method because in base class I don't
know the key fields...

Actually you do. The new row is always placed at the bottom of DataTable.
So, get pk from the last row in DataView's underlying datatable and use it
in DataView.Find method.
Feasible?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top