Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
143800 | Apr 5,2019 06:43 AM UTC | Mar 2,2020 01:03 PM UTC | WinForms | 7 |
![]() |
Tags: SfDataGrid |
Query |
Solution | ||
How to Uncheck selected checkbox in sfDataGrid on Button Click Event. ? |
You can able to uncheck the selected checkbox from selected items by using the below code snippet.
If you want to unselect all the selected checkboxes in button click, you can refer the below code snippet.
| ||
How to Loop through selected checkbox rows of sfDataGrid? |
You can get the selected checkbox rows from SfDataGrid control by using the following code snippet,
|
this.sfDataGrid1.CellCheckBoxClick += sfDataGrid1_CellCheckBoxClick;
void sfDataGrid1_CellCheckBoxClick(object sender, CellCheckBoxClickEventArgs e)
{
var selectedRows = this.sfDataGrid1.View.Records.Where(item => (item.Data as OrderInfo).IsClosed == true).ToList();
var checkedItems = selectedRows.Count + (e.NewValue == CheckState.Checked ? 1 : -1);
GridCheckBoxColumn column = e.Column as GridCheckBoxColumn;
PropertyInfo info = column.GetType().GetProperty("HeaderState", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
if (checkedItems == this.sfDataGrid1.View.Records.Count)
{
info.SetValue(column, CheckState.Checked);
}
else
{
info.SetValue(column, CheckState.Unchecked);
}
}
|
sfDataGrid1.View.RecordPropertyChanged += View_RecordPropertyChanged;
void View_RecordPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsClosed")
{
var selectedRows = this.sfDataGrid1.View.Records.Where(item => (item.Data as OrderInfo).IsClosed == true).ToList();
GridCheckBoxColumn column = this.sfDataGrid1.Columns["IsClosed"] as GridCheckBoxColumn;
PropertyInfo info = column.GetType().GetProperty("HeaderState", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
if (selectedRows.Count == this.sfDataGrid1.View.Records.Count)
{
info.SetValue(column, CheckState.Checked);
}
else
{
info.SetValue(column, CheckState.Unchecked);
}
}
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.