Home › Forums › WinForms controls › Xceed Grid for WinForms › GridCheckBox in a InsertRow
-
AuthorPosts
-
#13378 |
In a InsertRow I want see the CheckBox value = true (not “indeterminate” like default).
Dim myCheckBox As New Xceed.Grid.Editors.GridCheckBox
myCheckBox.CheckState = CheckState.Checked
Grid1.Columns(“View”).CellEditor = myCheckBox
Grid1.Columns(“View”).CellViewer = myCheckBoxnot work 🙁
Thanks.
Imported from legacy forums. Posted by AndreaZ (had 2522 views)
Use the class below as a viewer, instead of GridCheckBox. You can only use it as a viewer, not as an editor. Set the <b>DefaultValue</b> property to the value you want to see displayed instead of <i>indeterminate</i>.
Use it like this:
Grid1.Columns[“View”].CellViewer = new CustomGridCheckBoxViewer();
<code>
public class CustomGridCheckBoxViewer : ICellViewer
{
private ICellViewer viewer;
private bool defaultValue;public CustomGridCheckBoxViewer()
{
viewer = new GridCheckBox();
defaultValue = true;
}public bool DefaultValue
{
get { return defaultValue; }
set { defaultValue = value; }
}#region ICellViewer Members
public int GetFittedHeight(Cell cell, Xceed.Grid.AutoHeightMode mode) { return viewer.GetFittedHeight(cell, mode); }
public int GetFittedWidth(Cell cell) { return viewer.GetFittedWidth(cell); }
public bool PaintCellValue(GridPaintEventArgs e, Cell cell)
{
if (!(cell.Value is bool)) cell = new CheckBoxCell(cell, defaultValue);
return viewer.PaintCellValue(e, cell);
}
#endregionprivate class CheckBoxCell : Cell
{
private bool value;
public CheckBoxCell(Cell cell, bool value):base(cell)
{
this.value = value;
HorizontalAlignment = cell.HorizontalAlignment;
VerticalAlignment = cell.VerticalAlignment;
BackColor = cell.GetBackColorToPaint();
ForeColor = cell.GetForeColorToPaint();
}protected override Cell CreateInstance() { return new CheckBoxCell(this, value); }
protected override object GetValue() { return value; }
protected override void SetValue(object value) { }
}
}
</code>Imported from legacy forums. Posted by Tommy (had 218 views)
Thanks!
Imported from legacy forums. Posted by AndreaZ (had 3462 views)
-
AuthorPosts
- You must be logged in to reply to this topic.