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

RadGridView - SQL updating problem

3 Answers 143 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Attila
Top achievements
Rank 2
Attila asked on 26 Oct 2016, 10:52 PM

Hello!

 

I have a problem updating my sql db with my radGridView after successful binding. One of my sql column has 'bit' type, so the radGridView has a column with checkboxes. After I check/uncheck one of the checkboxes, it doesn't update my SQL unless I select another cell. Is there any solution to this problem? I use this event:

 

private void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)        
{
             itemsTableAdapter.Update(telerikDataSet);
             ordersTableAdapter.Update(telerikDataSet);         
}

 

(I use table hierarchy. 'Orders' table is the parent, 'Items' table is the child. This is ok. I managed to solve that if I check the checkbox in the parent, all its child checkboxes will be checked too). This way:

 

private void radGridView1_ValueChanging(object sender, ValueChangingEventArgs e)         

{

            if (radGridView1.SelectedRows[0].Cells[3].ColumnInfo.HeaderText == "Closed")
           {
               if (radGridView1.SelectedRows[0].Cells["Closed"].IsCurrent)
               {
                   foreach (GridViewRowInfo item in radGridView1.SelectedRows)
                   {
                       GridViewHierarchyRowInfo hierarchyRow = item as GridViewHierarchyRowInfo;
                       if (hierarchyRow != null)
                       {
                           GridViewInfo currentView = hierarchyRow.ActiveView;
                           foreach (GridViewInfo view in hierarchyRow.Views)
                           {
                               hierarchyRow.ActiveView = view;
                               foreach (GridViewRowInfo row in hierarchyRow.ChildRows)
                               {
                                   radGridView1.ValueChanging -= radGridView1_ValueChanging;//without this getting infinite loop...
                                   row.Cells[4].Value = e.NewValue;
                                    ordersTableAdapter.Update(telerikDataSet);
                                    itemsTableAdapter.Update(telerikDataSet);
                                   radGridView1.ValueChanging += radGridView1_ValueChanging;
                               }
                           }
                           hierarchyRow.ActiveView = currentView;
                       }
                   }
               }
           }                    
}

Of course every other fields are working fine when I edit them: as soon as I hit enter, it updates SQL. But checkbox doesn't need enter...

Thanks for your help.

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Oct 2016, 11:44 AM
Hello Attila,

Thank you for writing.  

According to the provided information, I suppose that the GridViewCheckBoxColumn.EditMode property is set to OnValidate which is the default value. Thus, the value will be submitted only when the current cell changes or the grid looses focus. Set the GridViewCheckBoxColumn.EditMode property to OnValueChange and thus the changes will be submitted immediately.
 
I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Attila
Top achievements
Rank 2
answered on 04 Nov 2016, 08:24 AM

Dear Dess,

Thanks for your reply. My problem is, that this GridView has AutoGeneratedColumns (populated from SQL), so how can I set the property you wrote? Casting the gridview's column to GridViewCheckBoxColumn or how?

Thanks again

Attila

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Nov 2016, 12:16 PM
Hello Attila, 

Thank you for writing back. 

It doesn't matter that the columns are automatically generated. It is necessary to access the respective column and cast it to GridViewCheckBoxColumn in order to access the EditMode property which is relevant only for the GridViewCheckBoxColumn. Here is a sample code snippet:
DataTable dt = new DataTable();
//fill the data table
this.radGridView1.DataSource = dt;
((GridViewCheckBoxColumn)this.radGridView1.Columns["IsActive"]).EditMode = EditMode.OnValueChange;

I hope this information helps. If you have any additional questions, please let me know 

Regards,
Dess
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
GridView
Asked by
Attila
Top achievements
Rank 2
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Attila
Top achievements
Rank 2
Share this question
or