【问题标题】:DevComponents DotNetBar SuperGridControl: How to change just 1 row's background colorDevComponents DotNetBar SuperGridControl:如何仅更改 1 行的背景颜色
【发布时间】:2015-08-04 16:21:12
【问题描述】:

正如主题所示,我的 Windows 窗体上有一个 DevComponents DotNetBar SuperGridControl (SGC)。在那个 SGC 中,我有交替的行颜色。 SGC 中的一列具有布尔值(数据中的启用/禁用标志)。

我想更改标记为 false 布尔值的行的背景颜色。

我尝试用来执行此任务的代码:

    private void dgvSearchResults_PostRenderRow(object sender, GridPostRenderRowEventArgs e)
    {
        if (e.RenderParts != RenderParts.Background) { return; }

        var row = (GridRow)e.GridRow;

        if (((CustomerDTO)row.DataItem).Disabled)
        {
            //Try to figure out how to set the row color here.
        }
    }

其中令人讨厌的部分是该代码显然为 SGC 中的每一行运行两次。但是,除了那部分之外,当我进入 .Disabled 控制语句时,似乎没有任何方法可以更改我所在行的行颜色。

我希望有任何提示或建议。

【问题讨论】:

    标签: c# winforms dotnetbar


    【解决方案1】:

    所以我实际上确实整理了一个答案,结果证明它相当简单。我只是调用了错误的事件处理程序。下面的代码执行我在最初的问题中尝试的确切任务:

        private void dgvSearchResults_GetRowCellStyle(object sender, GridGetRowCellStyleEventArgs e)
        {
            if (e.StyleType != StyleType.Default) { return; }
    
            var row = e.GridRow as GridRow;
            if (row == null) { return; }
    
            if (((CustomerDTO)row.DataItem).Disabled) {
                e.Style.Background = new Background(Color.Tomato);
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2021-12-30
      • 1970-01-01
      • 1970-01-01
      • 2018-08-14
      • 2011-11-11
      • 1970-01-01
      • 2016-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多