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
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.
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
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.
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:
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
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.
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
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.
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 ?
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.