Home Forums WinForms controls Xceed Grid for WinForms GridCheckBox in a InsertRow

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #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 = myCheckBox

    not work 🙁

    Thanks.

    Imported from legacy forums. Posted by AndreaZ (had 2522 views)

    User (Old forums)
    Member
    Post count: 23064

    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);
    }
    #endregion

    private 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)

    User (Old forums)
    Member
    Post count: 23064

    Thanks!

    Imported from legacy forums. Posted by AndreaZ (had 3462 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.