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

Conditionally enabling disabling CellElement

2 Answers 259 Views
GridView
This is a migrated thread and some comments may be shown as answers.
AY
Top achievements
Rank 1
AY asked on 22 Feb 2010, 11:48 AM
I am trying to conditionally enable and disable a CellElement based on the previous cells value. The code below works fine if the number of rows visible on the GridView appear all on one screen. If the rows exceed one screen and are scrollable, I get a null reference exception on "rowInfo.Cells[7].CellElement.Enabled = false;". Any ideas why it might be happening or a perhaps a better way to do this would really be helpful.

foreach ( var rowInfo in radGridView1.MasterGridViewTemplate.Rows ) 
            { 
                if ( ( !( (bool)rowInfo.Cells[6].Value ) ) ) continue
                rowInfo.Cells[7].CellElement.Enabled = false
            } 
 
 radGridView1.Columns[6].IsVisible = false

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin Vasilev
Telerik team
answered on 24 Feb 2010, 03:26 PM
Hi Akuila Yabaki,

Thank you for writing.  You have experience that behavior because RadGridView uses virtualization for its cell elements and at a given time only visible cell elements have been created. In your scenario, you have to use CellFormatting event:

void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement.ColumnIndex == 7 && 
        e.CellElement.RowInfo.Cells[6].Value is Boolean && 
        (bool)e.CellElement.RowInfo.Cells[6].Value)
    {
        e.CellElement.Enabled = false;
    }
    else
    {
        e.CellElement.Enabled = true;
    }
}

Hope this helps. Do not hesitate to contact me again if you have any additional questions.

Kind regards,
Martin Vasilev
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.
0
AY
Top achievements
Rank 1
answered on 13 Mar 2010, 12:44 PM
Thanks Martin,

It works like a charm.
Tags
GridView
Asked by
AY
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
AY
Top achievements
Rank 1
Share this question
or