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

Radgrid cell formatting problem

1 Answer 149 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Karthik
Top achievements
Rank 1
Karthik asked on 26 Oct 2012, 07:04 PM
Hi Telerik,
I have assigned some cols as read only in the radgrid(radform) and i used cell formatting to apply colors like this by name:
DTURradGridView.Columns["dtuct0"].ReadOnly = true;
          DTURradGridView.Columns["dtuct1"].ReadOnly = true;
          DTURradGridView.Columns["dtuct2"].ReadOnly = true;
          DTURradGridView.Columns["dtuct3"].ReadOnly = true;
          DTURradGridView.Columns["dtuy"].ReadOnly = true;

if (e.CellElement.ColumnInfo is GridViewDataColumn)
            {
                if (e.CellElement.ColumnInfo.FieldName == "dtuct0" )
                {
                    e.CellElement.DrawFill = true;
                    e.CellElement.NumberOfColors = 1;
                    e.CellElement.BackColor = Color.LightSlateGray;
                    e.CellElement.GradientStyle = GradientStyles.Linear;
                }
                if (e.CellElement.ColumnInfo.FieldName == "dtuct1")
                {
                    e.CellElement.DrawFill = true;
                    e.CellElement.NumberOfColors = 1;
                    e.CellElement.BackColor = Color.LightSlateGray;
                    e.CellElement.GradientStyle = GradientStyles.Linear;
                }
                if (e.CellElement.ColumnInfo.FieldName == "dtuct2")
                {
                    e.CellElement.DrawFill = true;
                    e.CellElement.NumberOfColors = 1;
                    e.CellElement.BackColor = Color.LightSlateGray;
                    e.CellElement.GradientStyle = GradientStyles.Linear;
                }
                if (e.CellElement.ColumnInfo.FieldName == "dtuct3")
                {
                    e.CellElement.DrawFill = true;
                    e.CellElement.NumberOfColors = 1;
                    e.CellElement.BackColor = Color.LightSlateGray;
                    e.CellElement.GradientStyle = GradientStyles.Linear;
                }
                if (e.CellElement.ColumnInfo.FieldName == "dtuy")
                {
                    e.CellElement.DrawFill = true;
                    e.CellElement.NumberOfColors = 1;
                    e.CellElement.BackColor = Color.LightSlateGray;
                    e.CellElement.GradientStyle = GradientStyles.Linear;
                }
            }

Then i want to hide/unhide based on the selection like this:
private void normalToolStripMenuItem_Click(object sender, EventArgs e)//Normal View
        {
            DTURradGridView.Columns["dtuct0"].IsVisible = false;
            DTURradGridView.Columns["dtuct1"].IsVisible = false;
            DTURradGridView.Columns["dtuct2"].IsVisible = false;
            DTURradGridView.Columns["dtuct3"].IsVisible = false;
            DTURradGridView.Columns["dtuy"].IsVisible = false;
 
        }
 
         
 
        private void advancedToolStripMenuItem_Click(object sender, EventArgs e) //Advanced View
        {
            DTURradGridView.Columns["dtuct0"].IsVisible = true;
            DTURradGridView.Columns["dtuct1"].IsVisible = true;
            DTURradGridView.Columns["dtuct2"].IsVisible = true;
            DTURradGridView.Columns["dtuct3"].IsVisible = true;
            DTURradGridView.Columns["dtuy"].IsVisible = true;
 
      
        }
When i Click on Normal Mode function, it applies colors to other cols. This is really strange for me. Please help me, thank you.

1 Answer, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 07 Nov 2012, 11:16 AM
Hello,

Because the grid view's cells are virtualized, the grid reuses cell, so you need to reset the colors of the cell if none of the conditions match your case.

// previous code from cell formatting
if (...)
{
     ...
}
else
{
      e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
      // and also reset any other value you have set manually
}

If you have any other questions, please let me know.


Best Regards,
Emanuel Varga
Winforms MVP
Tags
GridView
Asked by
Karthik
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Share this question
or