This is a migrated thread and some comments may be shown as answers.

Keeping track of edited rows

4 Answers 187 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Maziar
Top achievements
Rank 1
Maziar asked on 14 May 2011, 08:14 AM
Hi all,

I might be a little newbie to Telerik Winform controls, so please pardon me in advance.

I want to keep track of the edited rows, which means I want to insert new rows or update existing ones on a user button click. My data grid is not bound to a data set or something. the table in database in completely dynamic and will be created based on some meta data.
I did not find any flag in GridViewRowInfo class which can be used. (there is a IsModified flag which is always false)

So I created a List of edited rows and worked with that.
first I tried to save row indices. but I found out that the newly inserted row will have RowIndex = -1, but in save time will not be reachable.
so I decided to save the row reference in that List.
it did not work out, too. because the newly added row will change after it is really inserted into the grid. (a copy of the row will be added to grid not the row itself.) and I will insert a copy of an invalid row with no useful data.

I'd be thankful if someone helps me in this issue.


thanks.
Maziar



 

4 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 16 May 2011, 08:27 AM
Hello Maziar,

There are 2 different approaches i would suggest here:
- 1st and the easiest one is to create another bool column (hidden), something like IsModified where whenever you start an edit operation on a Row, and whenever something changes in the row you just set that flag to true, and on save, just set it to false.
- 2nd and this is the one i would suggest is to just add a property to your class, something the same, IsModified, or IsDirty and on property change just set that one to true, and again, on save, just reset that property. ( I would suggest using an interface to accomplish this).

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 16 May 2011, 09:37 AM
Hello Maziar,

Please have a look at this help topic which explains how to track changes in RadGridView.
If you need further help, please let me know
Thanks
Richard
0
Maziar
Top achievements
Rank 1
answered on 16 May 2011, 06:01 PM
Hi

Dear Emanuel,
Thank you for your post, but actually my question was if there are facilities embedded in grid view for such a situation. and as I said the table is completely dynamic and has no specific object in behind.
Anyway thanks for you time.

And Dear Richard,
Thank you, too. Yes I tried to use some of those events mentioned on that help page and also UserDeletingRow.

Last thing that I have done was keeping 2 lists, a edited items and deleted items. in my save method, I commit these changes, and for inserted rows, since the Tag object of the row is null, I insert it.

Thanks to both of you.
Maziar

ps - and guys there is a problem with RowIndex of a cell, and Index of a row. They randomly return zero or invalid value, 
Also the ColumnIndex of a cell is sometimes wrong but the ColumnInfo.Index is always right. interesting ... 
 I use 2011 Q1 SP1. have you heard about that? 
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 17 May 2011, 09:15 AM
Hello,

I'm glad you have found a solution for tracking changes.
Regarding the RowIndex, as far as I know there are no issues with RowIndex. Can you provide a small sample that demonstrates your issue and I'll be happy to take a look at it for you.

Thanks
Richard
Tags
GridView
Asked by
Maziar
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Maziar
Top achievements
Rank 1
Share this question
or