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

Drawing issue when cells disabled

2 Answers 68 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nordy
Top achievements
Rank 1
Nordy asked on 07 Feb 2008, 04:56 PM
I have the following code:

private void gridAttributes_RowFormatting(object sender, RowFormattingEventArgs e) 
        { 
            AttributeBase obj = e.RowElement.RowInfo.DataBoundItem as AttributeBase; 
            GridCellElement cell = null
 
            if (obj.DataType == "varchar"
                cell = e.RowElement.RowInfo.Cells[2].CellElement; 
            else if (obj.DataType == "bit"
                cell = e.RowElement.RowInfo.Cells[1].CellElement; 
 
            cell.Enabled = false
            cell.DrawFill = true
            cell.GradientStyle = Telerik.WinControls.GradientStyles.Solid; 
            cell.BackColor = SystemColors.ControlLightLight; 
        } 

It works fine on initially setting up which cells should be enabled or disabled, either cell 1 or cell 2 will be enabled, but not both.  The problem comes when I've got enough rows to cause a vertical scroll bar to appear.  As I scroll down, BOTH cells will be disabled.  Then as I scroll up and down, the problem works its way up the grid until all cells in columns 1 and 2 are disabled and grayed.

Any ideas?  Thanks.  Please let me know if you need more info.

2 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 07 Feb 2008, 06:34 PM
Hi Jamie,

Thank you for asking this question.

When dealing with cells in RadGridView it is better to use the CellFormatting event. It is also a requirement to reset any changes to the cell's style when your condition is not applicable.

I updated slightly your code. Consider the following code snippet:

void rgv_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e) 
   GridCellElement cell = e.CellElement; 
   AttributeBase obj = cell.RowElement.RowInfo.DataBoundItem as AttributeBase; 
 
   if (obj.DataType == "varchar" && cell.ColumnIndex == 2 || 
       obj.DataType == "bit" && cell.ColumnIndex == 1) 
   { 
       cell.Enabled = false
       cell.DrawFill = true
       cell.GradientStyle = Telerik.WinControls.GradientStyles.Solid; 
       cell.BackColor = SystemColors.ControlLightLight; 
   } 
   else 
   { 
       cell.DrawFill = false
   } 

Hope this helps. Do not hesitate to contact us if you have other questions.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Nordy
Top achievements
Rank 1
answered on 07 Feb 2008, 06:49 PM
Thanks for the quick reply!  I went ahead and changed my code to use CellFormatting instead of RowFormatting as you suggested, and changed your code further by adding cell.Enabled = true to the else statement under cell.DrawFill = false.  Now that I see it, it makes sense.

Thanks again.
Tags
GridView
Asked by
Nordy
Top achievements
Rank 1
Answers by
Jack
Telerik team
Nordy
Top achievements
Rank 1
Share this question
or