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

Checkbox in radgridview

16 Answers 1243 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Walter
Top achievements
Rank 1
Walter asked on 04 Oct 2011, 10:40 AM
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

16 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 05 Oct 2011, 07:19 AM
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
0
Walter
Top achievements
Rank 1
answered on 06 Oct 2011, 07:14 AM
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

0
Emanuel Varga
Top achievements
Rank 1
answered on 06 Oct 2011, 10:42 AM
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
0
Walter
Top achievements
Rank 1
answered on 07 Oct 2011, 02:43 AM
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..
0
Walter
Top achievements
Rank 1
answered on 07 Oct 2011, 02:47 AM
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
0
Accepted
Martin Vasilev
Telerik team
answered on 07 Oct 2011, 12:08 PM
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 >>

0
Walter
Top achievements
Rank 1
answered on 08 Oct 2011, 02:47 AM
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..
0
Martin Vasilev
Telerik team
answered on 12 Oct 2011, 01:51 PM
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.

0
Sasireka
Top achievements
Rank 1
answered on 19 Jan 2013, 09:37 AM
Hi all,

Could by please tell me on how to get the event (checked / unchecked) of checkbox within the gridview?.
0
Plamen
Telerik team
answered on 24 Jan 2013, 08:00 AM
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.
0
Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
answered on 18 Mar 2020, 01:57 PM

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

 

0
Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
answered on 18 Mar 2020, 02:00 PM
[quote]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

 

[/quote] 

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.  

1
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Mar 2020, 10:28 AM

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.
0
NTSAdmin
Top achievements
Rank 1
answered on 19 Mar 2020, 04:11 PM
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.
0
Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
answered on 19 Mar 2020, 04:14 PM
I am with Matt, how does one set that value? At what time? What Event?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 20 Mar 2020, 09:34 AM

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.
Tags
GridView
Asked by
Walter
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Walter
Top achievements
Rank 1
Martin Vasilev
Telerik team
Sasireka
Top achievements
Rank 1
Plamen
Telerik team
Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
Dess | Tech Support Engineer, Principal
Telerik team
NTSAdmin
Top achievements
Rank 1
Share this question
or