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

RowState Question

4 Answers 134 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 20 Feb 2009, 08:41 PM
I've been unable to find specifics in the documentation for how the underlying data rows get updated when binding an editable grid to a dataTable.  I have a problem where I retrieve a dataTable, call AcceptChanges() on it, bind it to the grid and the data shows properly.  When the user edits row cells and clicks the save button, the RowState properties on the underlying dataTable are not set to Modified as they should be.

Is there an Update Mode property or something I'm missing? I've tried clicking elsewhere inside and outside of the grid after editing and the rowState remains unchanged.  Ideas?


EDIT:  The following code appears to fix it. It's called just before saving:

foreach (GridViewRowInfo row in grd.MasterGridViewTemplate.Rows)  
{  
    DataRow dr = ((System.Data.DataRowView)(row.DataBoundItem)).Row;  
    dr.EndEdit();  

Is this the right way I should be handling this? Seems a little kludgy...Thx

4 Answers, 1 is accepted

Sort by
0
Accepted
Nick
Telerik team
answered on 23 Feb 2009, 06:07 PM
Hello Bill,

Thank you for contacting us. It is an issue and I have updated your Telerik points for bringing this to our attention. Fortunately, it seems that there is an easy work-around. The issue is present only for the current row. So you have to only make sure that you manually set the current row to modified if it was changed. Here is the code that you need:

 ((IEditableObject)this.radGridView1.CurrentRow.DataBoundItem).EndEdit(); 
 

Here is the code used to test the work-around:

DataTable s; 
 
private void Form1_Load(object sender, EventArgs e) 
            s = new DataTable(); 
            s.Columns.Add("A"); 
 
            s.Rows.Add("row 1"); 
            s.Rows.Add("row 2"); 
            s.Rows.Add("row 3"); 
 
            s.AcceptChanges(); //redundant 
             
            this.radGridView1.DataSource = s; 
 
private void radButton1_Click(object sender, EventArgs e) 
            ((IEditableObject)this.radGridView1.CurrentRow.DataBoundItem).EndEdit(); 
            foreach (DataRow row in s.Rows) 
            { 
                if (row.RowState == DataRowState.Modified)  
                { 
                    MessageBox.Show(row[0].ToString()); 
                } 
            } 
         

Do not hesitate to write me back if you need further assistance.

Greetings,
Nick
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Bill
Top achievements
Rank 1
answered on 23 Feb 2009, 06:10 PM
It worked. Thank you...
0
MP
Top achievements
Rank 1
answered on 18 Feb 2011, 03:58 PM
Dear Nick,

Is this still an issue in the latest release? If so, is this going to be fixed in a subsequent release?

Thanks,
MP
0
Julian Benkov
Telerik team
answered on 23 Feb 2011, 08:18 AM
Hello MP,

The edit operation of current row is committed after the current row position is changed to another row. For example, if your current row is 'row0' and after you edit it you your go to 'row1', EndEdit operation is called automatically in RadGridView control. In the scenario where you want the edit operation to change underline data immediately, you can handle CellValueChanged event and call the EndEdit method on IEditableObject there:

((IEditableObject)this.radGridView1.CurrentRow.DataBoundItem).EndEdit();

This the normal behavior for CRUD operations and our implementation is like the standard DataGridView control.

I hope this was helpful.

Greetings,
Julian Benkov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
GridView
Asked by
Bill
Top achievements
Rank 1
Answers by
Nick
Telerik team
Bill
Top achievements
Rank 1
MP
Top achievements
Rank 1
Julian Benkov
Telerik team
Share this question
or