Hi,
I have a hierarchical gridview with checkbox column. I have a checkbox in header as well.
When the header checkbox is checked/unchecked all other rows gets checked/unchecked accordingly.
But when i do the same in Child it is not working properly.
When i check/uncheck header of Child then the child rows of only expanded row should get checked/unchecked but not all the child rows.
Right now its applying changes for all child rows but i want it only for expanded row.
Below is my code:
<
private void AddCheckColumn(fc_rad_dataGridView dataGridView)
{
CustomCheckBoxColumn checkColumn = new CustomCheckBoxColumn();
checkColumn.Name = "IsActive";
checkColumn.FieldName = "Active";
if (!dataGridView.Columns.Contains("IsActive"))
dataGridView.Columns.Insert(dataGridView.Columns.Count - 1, checkColumn);
}
public class CustomCheckBoxColumn : GridViewCheckBoxColumn
{
public override Type GetCellType(GridViewRowInfo row)
{
if (row is GridViewTableHeaderRowInfo)
{
return typeof(CheckBoxHeaderCell);
}
return base.GetCellType(row);
}
}
public class CheckBoxHeaderCell : GridHeaderCellElement
{
RadCheckBoxElement checkbox;
protected override Type ThemeEffectiveType
{
get
{
return typeof(GridHeaderCellElement);
}
}
public CheckBoxHeaderCell(GridViewColumn column, GridRowElement row)
: base(column, row)
{
}
public override void Initialize(GridViewColumn column, GridRowElement row)
{
base.Initialize(column, row);
column.AllowSort = false;
column.TextAlignment = ContentAlignment.MiddleRight;
}
public override void SetContent()
{
}
protected override void DisposeManagedResources()
{
checkbox.ToggleStateChanged -= new StateChangedEventHandler(checkbox_ToggleStateChanged);
base.DisposeManagedResources();
}
protected override void CreateChildElements()
{
base.CreateChildElements();
checkbox = new RadCheckBoxElement();
checkbox.ToggleStateChanged += new StateChangedEventHandler(checkbox_ToggleStateChanged);
this.Children.Add(checkbox);
}
protected override SizeF ArrangeOverride(SizeF finalSize)
{
SizeF size = base.ArrangeOverride(finalSize);
RectangleF rect = GetClientRectangle(finalSize);
this.checkbox.Arrange(new RectangleF((finalSize.Width - this.checkbox.DesiredSize.Width) / 2, (rect.Height - 20) / 2, 20, 20));
return size;
}
public override bool IsCompatible(GridViewColumn data, object context)
{
return data.Name == "IsActive" && context is GridTableHeaderRowElement
&& base.IsCompatible(data, context);
}
private void checkbox_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
if (this.ColumnInfo is GridViewCheckBoxColumn)
{
bool valueState = false;
if (args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
{
valueState = true;
}
for (int i = 0; i < this.ViewTemplate.Rows.Count; i++)
{
this.ViewTemplate.Rows[i].Cells[this.ColumnIndex].Value = valueState;
}
}
}
}
>
Thanks,
Pinaki
I have a hierarchical gridview with checkbox column. I have a checkbox in header as well.
When the header checkbox is checked/unchecked all other rows gets checked/unchecked accordingly.
But when i do the same in Child it is not working properly.
When i check/uncheck header of Child then the child rows of only expanded row should get checked/unchecked but not all the child rows.
Right now its applying changes for all child rows but i want it only for expanded row.
Below is my code:
<
private void AddCheckColumn(fc_rad_dataGridView dataGridView)
{
CustomCheckBoxColumn checkColumn = new CustomCheckBoxColumn();
checkColumn.Name = "IsActive";
checkColumn.FieldName = "Active";
if (!dataGridView.Columns.Contains("IsActive"))
dataGridView.Columns.Insert(dataGridView.Columns.Count - 1, checkColumn);
}
public class CustomCheckBoxColumn : GridViewCheckBoxColumn
{
public override Type GetCellType(GridViewRowInfo row)
{
if (row is GridViewTableHeaderRowInfo)
{
return typeof(CheckBoxHeaderCell);
}
return base.GetCellType(row);
}
}
public class CheckBoxHeaderCell : GridHeaderCellElement
{
RadCheckBoxElement checkbox;
protected override Type ThemeEffectiveType
{
get
{
return typeof(GridHeaderCellElement);
}
}
public CheckBoxHeaderCell(GridViewColumn column, GridRowElement row)
: base(column, row)
{
}
public override void Initialize(GridViewColumn column, GridRowElement row)
{
base.Initialize(column, row);
column.AllowSort = false;
column.TextAlignment = ContentAlignment.MiddleRight;
}
public override void SetContent()
{
}
protected override void DisposeManagedResources()
{
checkbox.ToggleStateChanged -= new StateChangedEventHandler(checkbox_ToggleStateChanged);
base.DisposeManagedResources();
}
protected override void CreateChildElements()
{
base.CreateChildElements();
checkbox = new RadCheckBoxElement();
checkbox.ToggleStateChanged += new StateChangedEventHandler(checkbox_ToggleStateChanged);
this.Children.Add(checkbox);
}
protected override SizeF ArrangeOverride(SizeF finalSize)
{
SizeF size = base.ArrangeOverride(finalSize);
RectangleF rect = GetClientRectangle(finalSize);
this.checkbox.Arrange(new RectangleF((finalSize.Width - this.checkbox.DesiredSize.Width) / 2, (rect.Height - 20) / 2, 20, 20));
return size;
}
public override bool IsCompatible(GridViewColumn data, object context)
{
return data.Name == "IsActive" && context is GridTableHeaderRowElement
&& base.IsCompatible(data, context);
}
private void checkbox_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
if (this.ColumnInfo is GridViewCheckBoxColumn)
{
bool valueState = false;
if (args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
{
valueState = true;
}
for (int i = 0; i < this.ViewTemplate.Rows.Count; i++)
{
this.ViewTemplate.Rows[i].Cells[this.ColumnIndex].Value = valueState;
}
}
}
}
>
Thanks,
Pinaki