views:

1520

answers:

2

I have a GridControl view which is being populated with one column as a Boolean to show the value as a checkbox.

However, I wish to hide some checkboxes based on the state of other columns. I have tried to use the gridView_CustomDrawCell() event but cannot find a suitable property.

I expected to find a visible property to set to false but there doesn't seem to be one.

Maybe it is possible to hide the checkbox when the view is being populated but I cannot think of one.

Does anyone know if this is possible, and how?

Many thanks!

+3  A: 

You could try to clear the Graphics and mark the event as handled :

private void gridView_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
{
    if (ConditionIsMet())
    {
        e.Graphics.Clear(e.Appearance.BackColor);
        e.Handled = true;
    }
}

If it doesn't work, here's another idea : handle the CustomRowCellEdit and CustomRowCellEditForEditing events, and remove the editor :

private void gridView_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e)
{
    if (ConditionIsMet())
    {
        e.RepositoryItem = null;
    }
}
Thomas Levesque
+1 for using CustomRowCellEditForEditing event.
Sergey Mirvoda
Wow, I've been using this product for over 3 years and never realized that you could set `RepositoryItem` to `null`, I've always just created a default item for disabled editors. This will save me some time!
Aaronaught
@Aaronaught, I don't know if this actually works, it's just a suggestion ;)
Thomas Levesque
I have tried setting the Repository Item to null but it doesn't work. It uses default editor, probably based on the corresponding property type.
Koynov
OK, so you will probably have to assign an empty editor instead...
Thomas Levesque
Thanks Thomas, the e.handled=true method worked. Thanks to all for your help.
+2  A: 

What I did for this on a project was to set a RadioGroup as the control with no items so it appeared as blank.

private void viewTodoList_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
        {
            if (e.Column == CheckMarkColumn)
            {
                if (ConditionIsMet())
                {
                    e.RepositoryItem = new DevExpress.XtraEditors.Repository.RepositoryItemRadioGroup();
                }
            }
        }
Gary L Cox Jr