This sample shows how to bind checkboxes in HierachyColumn:
[c#]
public class BoundCheckBoxColumn : HierachyColumn
{
public BoundCheckBoxColumn(string name) : base(name){}
public BoundCheckBoxColumn(string name, string fieldName) : base(name, fieldName){}
private string checkBoxFieldName = string.Empty;
[DefaultValue(\"\")]
public string CheckBoxFieldName
{
get
{
return checkBoxFieldName;
}
set
{
if (checkBoxFieldName != value)
{
checkBoxFieldName = value;
base.OnChanged(InvalidationMode.FullColumn, false);
}
}
}
public override void OnCheckBoxClick(FlyGrid flyGrid, NodeBase node)
{
base.OnCheckBoxClick(flyGrid, node);
DataRowView drv = node.Value as DataRowView;
if (drv != null)
{
ButtonState cbs = node.Checked ? ButtonState.Checked : ButtonState.Normal;
drv[CheckBoxFieldName] = cbs;
}
}
protected override void PaintCheckBox(CellDrawInfo dci)
{
if (CheckBoxFieldName != string.Empty)
{
Rectangle r = base.CheckBoxRect(dci.node, dci.cellRect, dci.RightToLeft);
DataRowView drv = dci.node.Value as DataRowView;
if (drv != null)
{
object cellvalue = drv[CheckBoxFieldName];
ButtonState cbs = (ButtonState)cellvalue;
cbs |= ButtonState.Flat;
ControlPaint.DrawCheckBox(dci.g, r, cbs);
}
}
else
{
base.PaintCheckBox(dci);
}
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
InitFlyGrid(flyGrid);
}
private void InitFlyGrid(FlyGrid flyGrid)
{
flyGrid.BeginInit();
try
{
BoundCheckBoxColumn boundCheckBoxColumn = new BoundCheckBoxColumn(\"Value\");
//setup column
boundCheckBoxColumn.CheckBoxFieldName = \"CheckBoxValue\";
boundCheckBoxColumn.ShowCheckBoxes = true;
//fit to width
boundCheckBoxColumn.FitMode = ColumnFitMode.Spring;
flyGrid.Columns.Options |= ColumnsOptions.FitToWidth;
//hide AddNewRow row
flyGrid.Rows.Options &= ~ RowsOptions.ShowAddNewRow;
//add column
flyGrid.Columns.Items.Add(boundCheckBoxColumn);
//create and setup datatable
DataTable dt = new DataTable(\"Data\");
DataColumn dc = new DataColumn(\"Value\", typeof(string));
DataColumn dcb = new DataColumn(\"CheckBoxValue\", typeof(ButtonState));
dt.Columns.Add(dc);
dt.Columns.Add(dcb);
//fill data
for(int i=0; i < 10; i++)
{
object[] rowdata =
{
\"new row\" + i,
i % 2 == 0 ? ButtonState.Checked : ButtonState.Checked | ButtonState.Inactive
};
dt.Rows.Add(rowdata);
}
flyGrid.Rows.DataSource = dt;
}
finally
{
flyGrid.EndInit();
}
}