Checkbox in radgridview

17 posts, 1 answers
  1. Walter
    Walter avatar
    7 posts
    Member since:
    Oct 2011

    Posted 04 Oct 2011 Link to this post

    Hello guys!!

    I need some helps. I want make checkbox in main radgridview
    when i checked it, all checkbox inside gridviewtemplate will checked too.
    in radgridview i use group by, and how i can select checkbox based on group radgridview?
    i attached my problem too

     any suggestions?

    thanks
  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 05 Oct 2011 Link to this post

    Hello Walter,

    A couple of questions,

    Is that checkbox bound or not?
    Is the hierarchy an object hierarchy or manually created hierarchy?

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP
  3. Walter
    Walter avatar
    7 posts
    Member since:
    Oct 2011

    Posted 06 Oct 2011 Link to this post

    Thanks for response

    1. I use gridview checkbox column, is the right way or not?
    2. Yes I use object hierarchy in radgrid

    I want save them all in one table, so i have 2 field bit data type,
    one for save chekbox in column "status" at my picture,
    and other to save checkbox in column "statuswip"

    Best Regards,
    Walter

  4. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 06 Oct 2011 Link to this post

    Hello Walter,

    Could you please create a small sample app and post it here, it would be a lot faster and easier like that...

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

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP
  5. Walter
    Walter avatar
    7 posts
    Member since:
    Oct 2011

    Posted 06 Oct 2011 Link to this post

    Hello Varga,

    I can't attach my sample application because allowed extensions are : .gif, .jpg, .jpeg and .png..
    My sample code is:

    Imports Telerik.WinControls.UI
    Imports Telerik.Data
    Public Class Form1

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim xCity As DataTable
            Dim xCountry As DataTable
            Dim xConnection As New Koneksi


            xCity = xConnection.ExecuteQuery("Select distinct Country.CountryID, CityID, statusCity  from City,Country  where Country.CountryID = City.CountryID")
            xCountry = xConnection.ExecuteQuery("Select distinct Country.CountryID, statusCountry from Country, City where Country.CountryID = City.CountryID")
            RadGridView1.DataSource = xCountry
            Dim template As New GridViewTemplate()
            template.DataSource = xCity
            RadGridView1.MasterTemplate.Templates.Add(template)
            Dim relation As New GridViewRelation(RadGridView1.MasterTemplate)
            relation.ChildTemplate = template
            relation.RelationName = "CountryCity"
            relation.ParentColumnNames.Add("CountryID")
            relation.ChildColumnNames.Add("CountryID")
            RadGridView1.Relations.Add(relation)
        End Sub
    End Class

    I want if i checked statusCountry, all of statusCity must be checked too..

    I use SQL Server R2 for my connection. The authentication is Windows Authentication. File "connection.txt" is the server name of your computer.

    Wish any good news from you..
    Cheers..
  6. Walter
    Walter avatar
    7 posts
    Member since:
    Oct 2011

    Posted 06 Oct 2011 Link to this post

    Oh I forgot.. This is my screen capture..

    My problem is how to checked all of "StatusCity" if I've already checked "StatusCountry"?

    Wish any good news from you.. Cheers
  7. Answer
    Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 07 Oct 2011 Link to this post

    Hello Walter,

    You may consider using the ValueChanged event and ChildRows collection in order to implement the desired functionality:
    Private Sub RadGridView1_CellValueChanged(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles RadGridView1.CellValueChanged
        If e.Column.Name = "StatusCountry" Then
            For Each row As GridViewDataRowInfo In e.Row.ChildRows
                row.Cells("StatusCity").Value = e.Value
            Next
        End If
    End Sub

    I hope this helps. Let me know if you have any additional questions.

    Regards,
    Martin Vasilev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Walter
    Walter avatar
    7 posts
    Member since:
    Oct 2011

    Posted 07 Oct 2011 Link to this post

    Wow.. Thanks Martin..
    It's work..

    Hmm.. But i still have a simple problem..
    If i checked "StatusCountry" when my radgridview is expanded, i must scroll down or move to another row so "StatusCity" will checked all too.

    Can you help me to find the solution about triggering childrows without scroll down or something like that??

    Because i've already tried "radgridview1.refresh()" but it doesn't work.. Wish any good news from you.. Cheers..
  9. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 12 Oct 2011 Link to this post

    Hi Walter,

    Thank you for getting back to me.

    If you want to change the check-state of the child rows immediately after checking/unchecking the parent row there is a slightly different approach which could match your requirement. Please consider the code bellow:
    Private currentCheckEditor As RadCheckBoxEditor
     
    Private Sub radGridView1_CellBeginEdit(sender As Object, e As GridViewCellCancelEventArgs) Handles radGridView1.CellBeginEdit
        Me.currentCheckEditor = TryCast(e.ActiveEditor, RadCheckBoxEditor)
        If e.Column.Name = "StatusCountry" AndAlso Me.currentCheckEditor IsNot Nothing Then
            AddHandler Me.currentCheckEditor.ValueChanged, AddressOf editor_ValueChanged
        End If
    End Sub
     
    Private Sub radGridView1_CellEndEdit(sender As Object, e As GridViewCellEventArgs) Handles radGridView1.CellEndEdit
        If Me.currentCheckEditor IsNot Nothing Then
            RemoveHandler Me.currentCheckEditor.ValueChanged, AddressOf editor_ValueChanged
            Me.currentCheckEditor = Nothing
        End If
    End Sub
     
    Private Sub editor_ValueChanged(sender As Object, e As EventArgs)
        Dim editor As RadCheckBoxEditor = DirectCast(sender, RadCheckBoxEditor)
        Dim value As ToggleState = DirectCast(editor.Value, ToggleState)
        For Each row As var In Me.radGridView1.CurrentRow.ChildRows
            row.Cells("StatusCity").Value = value = ToggleState.[On]
        Next
    End Sub

    Write me back if you need any additional assistance.

    Greetings,
    Martin Vasilev
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  10. Sasireka
    Sasireka avatar
    17 posts
    Member since:
    Nov 2012

    Posted 19 Jan 2013 Link to this post

    Hi all,

    Could by please tell me on how to get the event (checked / unchecked) of checkbox within the gridview?.
  11. Plamen
    Admin
    Plamen avatar
    132 posts

    Posted 24 Jan 2013 Link to this post

    Hello Sasireka,

    Thank you for writing.

    You could use the ValueChanged event to track when some editor, including checkbox changes its value in RadGridView. Here is a sample code:
    void radGridView1_ValueChanged(object sender, EventArgs e)
    {
          RadCheckBoxEditor editor = sender as RadCheckBoxEditor;
    if (editor != null)
    {
    //here the checkbox value is changed
               }
    }

    Off topic, please restrain from  mixing different subjects in the same thread. Please refer to p.4 from our forum guidelines: http://www.telerik.com/community/forums/winforms/gridview/important-information-on-using-the-telerik-forums.aspx

    I hope this helps.

    Kind regards,
    Plamen
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  12. Mark
    Mark avatar
    130 posts
    Member since:
    Oct 2014

    Posted 18 Mar Link to this post

    I know this is a bit old, but I am having a problem with "ValueChanged" event to fire when using a Hierarchical Grid and the check box is in the 3rd level of the Hierarchy and I change the value.  Is there a setting at the grid level that needs to be set?  Our grid is a subclass of RadGridView with a much of settings set that we commonly set.

     

    Thanks for the help

     

  13. Mark
    Mark avatar
    130 posts
    Member since:
    Oct 2014

    Posted 18 Mar in reply to Mark Link to this post

    Mark said:

    I know this is a bit old, but I am having a problem with "ValueChanged" event to fire when using a Hierarchical Grid and the check box is in the 3rd level of the Hierarchy and I change the value.  Is there a setting at the grid level that needs to be set?  Our grid is a subclass of RadGridView with a much of settings set that we commonly set.

     

    Thanks for the help

     

     

    The end result I am trying to do is change the text color if the check box in that row is checked, otherwise leave it the default color.  The problem I am having, is that the RowFormatting is not firing every time I check or uncheck the checkbox. I had read somewhere in the past that I would have to validate the row, but if I can't capture when the check box is actually checked or unchecked, because value change event is not firing.  

  14. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3907 posts

    Posted 19 Mar Link to this post

    Hello, Mark,

    Note that the GridViewCheckBoxColumn offers the EditMode property which controls when the value of the editor will be submitted to the cell. By default, the old behavior is kept (OnValidate) and the value will be submitted only when the current cell changes or the grid looses focus. The new value (OnValueChange) will submit the value immediately after the editor value changes. In this case, the grid wouldn't enter edit mode for the checkbox. Hence, the ValueChanged won't be fired. 

    I would recommend you to set the GridViewCheckBoxColumn.EditMode property to OnValueChange. Thus, when you toggle the checkbox, the value will be immediately committed to the cell. Then, you can handle the CellValueChanged event and perform the desired action. 

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  15. Mark
    Mark avatar
    1 posts
    Member since:
    Oct 2014

    Posted 19 Mar in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Exactly how do I change that?  I am looking for an event to when the control/column is created, but I don't seem to see an event that will allow me to change that value.
  16. Mark
    Mark avatar
    130 posts
    Member since:
    Oct 2014

    Posted 19 Mar Link to this post

    I am with Matt, how does one set that value? At what time? What Event?
  17. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3907 posts

    Posted 20 Mar Link to this post

    Hello, guys,

    When you populate the grid with, e.g. set the DataSource, it is expected that the columns are auto generated. Hence, after setting the DataSource, the RadGridView.Columns collection is expected to be filled with columns and you can access each column. It is necessary to cast the accessed column to GridViewCheckBoxColumn in order to have access to its EditMode property.
            private void RadForm1_Load(object sender, EventArgs e)
            {
                this.productsTableAdapter.Fill(this.nwindDataSet.Products);
    
                this.radGridView1.DataSource = this.productsBindingSource;
                GridViewCheckBoxColumn checkBoxColumn = this.radGridView1.Columns["Discontinued"] as GridViewCheckBoxColumn;
                checkBoxColumn.EditMode = EditMode.OnValueChange;
                this.radGridView1.CellEndEdit += RadGridView1_CellEndEdit;
            }
            private void RadGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
            {
            }
    I hope this information helps.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top