RadGridView - SQL updating problem

4 posts, 0 answers
  1. Attila
    Attila avatar
    1 posts
    Member since:
    Oct 2016

    Posted 26 Oct Link to this post

    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.

  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 27 Oct Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Attila
    Attila avatar
    4 posts
    Member since:
    Oct 2016

    Posted 04 Nov in reply to Dess Link to this post

    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

  5. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 04 Nov Link to this post

    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.
Back to Top