This is a migrated thread and some comments may be shown as answers.

Hiding Checkboxes for NULL DataSet entries..?

1 Answer 262 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ralph Katieb
Top achievements
Rank 1
Ralph Katieb asked on 21 Jul 2010, 05:52 PM
I have a standard WinForms DataSet being populated programatically (but bound at design-time to a discrete DataSet control on the .NET form). My question is simple: how can I hide (for example) the 2nd and 3rd checkboxes if these values are NULL values in the data for that row? If they are non-NULL, I want to present the checkbox and have it be editable. However, if they are NULL in the dataset I don't want the checkbox there at all.

I can't figure out a simple (or even non-simple) way of hiding these NULL-representing checkboxes. I have tried intercepting the cell formatting event programatically but setting the various e.CellElement._ values to hide/indicate invisible/set ShouldPaint to false/etc.. All efforts to hide these NULL-backed checkboxes seem to be completely ignored by the RadControls GridView. The GridView checkbox column just treats NULL as "false" and allows the user to click them / check them to "true" anyway.

Is there a simple way to conditionally NOT display the checkbox in a RadControls GridView checkbox column, so I can hide/show them for some rows but not for others..?  Help..?!

Many thanks in advance,

Ralph

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 26 Jul 2010, 04:11 PM
Hi Ralph Katieb,

You need to subscribe to the CellFormatting event where you can hide check box editor element depending on the your condition. You can use the following code snippet as a sample:
private void radGridView_CellFormatting(object sender, CellFormattingEventArgs e)
{
    GridCheckBoxCellElement chbCellElement = e.CellElement as GridCheckBoxCellElement;
    if (chbCellElement != null)
    {
        GridViewRowInfo row = e.CellElement.RowInfo as GridViewRowInfo;
        BaseGridEditor gridEditor = chbCellElement.Editor as BaseGridEditor;
 
        object value = row.Cells["Name"].Value;
 
        if (value == null || Convert.IsDBNull(value))
        {
            gridEditor.EditorElement.Visibility = ElementVisibility.Hidden;
        }
        else
        {
            gridEditor.EditorElement.Visibility = ElementVisibility.Visible;
        }
    }
}

All the best,
Svett
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Ralph Katieb
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or