Drawing issue when cells disabled

3 posts, 0 answers
  1. Nordy
    Nordy avatar
    14 posts
    Member since:
    Aug 2007

    Posted 07 Feb 2008 Link to this post

    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. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 07 Feb 2008 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Nordy
    Nordy avatar
    14 posts
    Member since:
    Aug 2007

    Posted 07 Feb 2008 Link to this post

    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.
Back to Top