如何为Radgridview列设置颜色 [英] How Do I Set Color For Radgridview Column

查看:257
本文介绍了如何为Radgridview列设置颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我使用此代码但我没有回答



hi i used this code but I did not answer

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

推荐答案

您好,我们通常设置背景颜色和其他单元格属性(例如,将控件隐藏在单元格中有条件地)在网格的CellFormatting事件。请检查以下代码:格式化单元格



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

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);
    }
}


请检查一下,希望它会有所帮助



http://stackoverflow.com/questions/ 13808407 / set-rowelement-backcolor-in-telerik-radgridview-winforms-in-rowformatting-even [ ^ ]



http://www.telerik.com/forums/change-the-color-of -rad-grid-view-column [ ^ ]
Pls check this, Hope it would help

http://stackoverflow.com/questions/13808407/set-rowelement-backcolor-in-telerik-radgridview-winforms-in-rowformatting-even[^]

http://www.telerik.com/forums/change-the-color-of-rad-grid-view-column[^]


请按照以下说明操作

1.选择Rad GridView

2.转到属性中的事件选项
3.单击cellFormatting事件并双击它。

它将生成如下代码



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

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


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);
           }


这篇关于如何为Radgridview列设置颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆