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

How can I select multiple check boxes in radgrid and select All

8 Answers 1099 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Anoop
Top achievements
Rank 1
Anoop asked on 26 Oct 2011, 10:35 AM

How can I select multiple check boxes in radgrid and select All

 

I am using RadGridview which view a data from sql database with one GridViewCheckBoxColumn.

 

Once the checkbox is clicked the whole row is deleted as I want, However I wanna allow that for multiple rows at the same time.

 

Also I want to select all

 

Is that possible?

 

In my grid I should click twice to check the box! How can I avoid that?

 

All the columns in the grid is read only except the checkbox column

 

Thanks and regards

8 Answers, 1 is accepted

Sort by
0
Accepted
Martin Vasilev
Telerik team
answered on 31 Oct 2011, 11:20 AM
Hi Anoop,

Thank you for writing.

I am not sure if I understand your scenario very well. However, if you need to add an unbound check-box column for selecting and deleting rows in RadGridView, you may take a look at following KB Article, which describes how to use check-box with a select all option:
Add "Check All" in the header cell for a GridViewCheckBoxColumn

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

Kind regards,
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
Shlomo Pleban
Top achievements
Rank 1
answered on 09 May 2013, 10:41 PM
Hi,

I added the class to my project.
Now I am trying to define the custom header column but it doesn't works for me ...

This is how I try to define the column:
var chkCol = new GridViewCheckBoxColumn
                                    {
                        AutoSizeMode = BestFitColumnMode.None,
                        Width = 40,
                        ThreeState = false,
                        AllowSort = false,
                        Name = "includeDataGridViewCheckBoxColumn",
                        FieldName = includeColumnName
                    };
   GridRowElement headerRow = null; // new GridRowElement();
   var hdrCell = new Input.DataGrid.CheckBoxHeaderCellTelerik(chkCol, headerRow);

What i want is to see in the checkbox column header the check box which select / un-select all

Thanks
0
Anton
Telerik team
answered on 14 May 2013, 12:55 PM
Hi Shlomo,

Thank you for writing.

I assume that you want to exchange the default header cell with your custom one. If so, your question has already been answered in the ticket "How do I add a custom cell to the grid header", but I am copying the answer here so the community can benefit from it.

There are two ways to use custom header cell in RadGridView:

1. Through custom column with a custom cell as described in the KB. This approach has several steps:

  •  Create custom column and override GetCellType method. This method exchange the type of the default header cell with the custom one.
Copy Code
public class CustomCheckBoxColumn : GridViewCheckBoxColumn
{
    public override Type GetCellType(GridViewRowInfo row)
    {
        if (row is GridViewTableHeaderRowInfo)
        {
            return typeof(CheckBoxHeaderCell);
        }
        return base.GetCellType(row);
    }
}
  • Insert your custom column in RadGridView. Consider the following code snippet:
Copy Code
private void AddCheckColumn()
{
    CustomCheckBoxColumn checkColumn = new CustomCheckBoxColumn();
    checkColumn.Name = "Select";
    checkColumn.HeaderText = "All";
    this.radGridView1.Columns.Insert(0, checkColumn);
}

2. Through the CreateCell event of RadGridView. This approach has several steps as well:
  • Add standard checkbox column - GridViewCheckBoxColumn
Copy Code
private void AddCheckColumn()
{
    GridViewCheckBoxColumn checkColumn = new GridViewCheckBoxColumn();
    checkColumn.Name = "Select";
    checkColumn.HeaderText = "All";
    this.radGridView1.Columns.Insert(0, checkColumn);
}
  • Subscribe to the CreateCell event of RadGridView and replacen the default GridHeaderCellElement with your custom one.
Copy Code
void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
{
    if (e.CellType == typeof(GridHeaderCellElement) && e.Column.HeaderText=="All")
    {
        e.CellType = typeof(CheckBoxHeaderCell);
    }
}

Attached is a sample project that comprises the code above.

We highly appreciate your effort to make more visible this topic for the community. However, we will be glad if you are using only one communication channel for your future support communication. 

If you have further questions, feel free to write back.

Greetings,
Anton
the Telerik team
RadChart for WinForms is obsolete. Now what?
0
cevdet
Top achievements
Rank 1
answered on 26 Jan 2015, 03:16 PM
How can I add CustomCheckBoxColumn to grid in design mode ? When I add in design mode column disappears.
0
Stefan
Telerik team
answered on 27 Jan 2015, 08:13 AM
Hi Cevdet,

Thank you for writing.

After placing the code for the custom column in a separate file and building the project you will be able to see the column in the Columns editor of RadGridView. From there, you can add it to the grid and it will be shown when you run the form. I have just tested this. If you experience any issues with this case, please open a support ticket and attach your project there for our team to investigate. 

As to the check box in the header cell, as of Q2 2014 SP1, RadGridView has this functionality built-in, so it is no longer needed to use custom column. Simply use the EnableHeaderCheckBox property of GridViewCheckBoxColumn.

Regards,
Stefan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
cevdet
Top achievements
Rank 1
answered on 27 Jan 2015, 11:40 AM
Hi Stefan,

Thank you for response.

After build project the column added and I saw it, but now there is another issue :

in checkbox_ToggleStateChanged event theese codes work successfully
                for (int i = 0; i < this.ViewInfo.Rows.Count; i++)
                {
                    this.ViewInfo.Rows[i].Cells[this.ColumnIndex].Value = valueState;
                }
I changed theese codes for my project than they did not worked. My codes related above codes :
List<int> Ids = this.GridControl.ChildRows.Select(O => (int)O.Cells["CUSTOMER_MAIN_ID"].Value).ToList();
foreach (DataRow Row in (this.GridControl.DataSource as DataTable).AsEnumerable().Where(O => Ids.Contains(O.Field<int>("CUSTOMER_MAIN_ID"))))
{
         Row["Select"] = valueState;
}

Shortly, customcheckboxcolumn does'nt work with datasource of radgridview in my project, please help me ?
0
Stefan
Telerik team
answered on 27 Jan 2015, 11:48 AM
As I mentioned, header check box is available out of the box with a single property setting, so you do not need to use custom column at all. Still, if you have to do that, please open a support ticket and send us your project and description of your goal, so we can investigate the precise case and help you with it.

Regards,
Stefan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
cevdet
Top achievements
Rank 1
answered on 27 Jan 2015, 11:59 AM
Ok, I understood it, but we can not upgrade telerik to Q2 2014 SP1 because we are not ready for this. I will try support ticket, thanks.
Tags
GridView
Asked by
Anoop
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Shlomo Pleban
Top achievements
Rank 1
Anton
Telerik team
cevdet
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or