Click here to Skip to main content
15,885,182 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi i used this code but I did not answer

C#
for (int i = 0; i <= radGridView1.Rows.Count - 1; i++)
          {
              if (i % 2 == 0)
              radGridView1.Rows[i].Cells[1].Style.BackColor = Color.Blue;
          }
Posted

Hi, we usually set the background color and other cell properties (For example hiding a control in a cell conditionally) at the CellFormatting event of the grid. Please check the below code i got from: Formatting Cells

C#
void radGridView1_CellFormatting2(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    if (e.CellElement.ColumnInfo.HeaderText == "Id")
    {
        if (e.CellElement.RowInfo.Cells["BMP"].Value != null)
        {
            if ((bool)e.CellElement.RowInfo.Cells["BMP"].Value == true)
            {
                e.CellElement.DrawFill = true;
                e.CellElement.ForeColor = Color.Blue;
                e.CellElement.NumberOfColors = 1;
                e.CellElement.BackColor = Color.Aqua;
            }
            else
            {
                e.CellElement.DrawFill = true;
                e.CellElement.ForeColor = Color.Yellow;
                e.CellElement.NumberOfColors = 1;
                e.CellElement.BackColor = Color.Green;
            }
        }
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.NumberOfColorsProperty, ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
    }
}
 
Share this answer
 
Comments
Member 11046620 17-Nov-14 6:35am    
I paint the individual columns
your code is true but when i run my program i have many column in radgridview and must use scroll for see them
when I move the scroll The colors are disgusting.
 
Share this answer
 
Comments
Member 11046620 17-Nov-14 6:36am    
I paint the individual columns
your code is true but when i run my program i have many column in radgridview and must use scroll for see them
when I move the scroll The colors are disgusting.
please follow the instruction as below
1. Select Rad GridView
2. Go to Events option in properties
3. Click on cellFormatting Event and double click on it.
It will generate code behind as below

C#
public void gResults_CellFormatting(object sender, CellFormattingEventArgs e)
      {

      }


do some logical cod here for me I have inserted a button based on other columns cell value


C#
if (e.Column.Name == "IsUpAndRunning")
           {
               if (((e.Row.ViewInfo.CurrentRow).DataBoundItem).ControlParameters != null)
               {
                   string isControllablevalue = (((e.Row.ViewInfo.CurrentRow).DataBoundItem)).ControlParameters.IsControlable.ToString();
                   if (isControllablevalue == "True")
                   {
                      e.CellElement.Text = "";
                      RadButtonElement btnOn = new RadButtonElement();
                      btnOn.Margin = new System.Windows.Forms.Padding(0, 1, 3, 1);
                       if ((e.CellElement.Value).ToString() == "True")
                       {
                           btnOn.Text = "On";
                       }
                       else
                       {
                           btnOn.Text = "Off";
                       }
                       e.CellElement.Children.Add(btnOn);
                   }
               }
               else
               {
                   if ((e.CellElement.Value).ToString() == "True")
                   {
                       e.CellElement.Text = "";
                       e.CellElement.Image = ((System.Drawing.Image)(resources.GetObject("picHMtrue.Image")));
                   }
                   else
                   {
                       e.CellElement.Text = "";
                       e.CellElement.Image = ((System.Drawing.Image)(resources.GetObject("picHMFalse.Image")));
                   }
               }
           }
           else
           {
               e.CellElement.ResetValue(LightVisualElement.ImageProperty, ValueResetFlags.Local);
           }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900