Checkbox in radgridview

11 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
    Member since:
    Sep 2012

    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
    Member since:
    Sep 2012

    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
    134 posts
    Member since:
    Nov 2012

    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.

Back to Top