如何在Datagridview行单元格中设置Backcolor [英] How to set Backcolor in Datagridview rows cells

查看:490
本文介绍了如何在Datagridview行单元格中设置Backcolor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



任何人都可以帮我解决我的问题。

我在子格式中有一个有界的数据网格视图。当我在mdi中加载子表单(使MdiParent = Me)时,我的自定义颜色的行不会显示。如果我删除MdiParent = Me然后着色工作。

Hi,
any one can help me on my problems.
I have a bounded datagridview in a child form. When I load the child form in the mdi (making MdiParent = Me) then my custom color of the rows does not show. If I remove MdiParent = Me then the coloring works.

{           DataTable dt = new DataTable();
           dt = genbl.GetReminderData();
           dgvReminderSetting.DataSource = dt;

           DataTable dt2 = new DataTable();
           DataColumn dc = dt2.Columns.Add("cl", typeof( Color));

           for (int i = 0; i < dt.Rows.Count; i++)
           {
               Color c = Color.FromArgb(Convert.ToInt32(dt.Rows[i].ItemArray[6].ToString()));


              dgvReminderSetting.Rows[i].Cells["ColorColumn"].Style.BackColor = c;
           }

           //Color.FromArgb(-8323073);
           this.Invalidate();
           dgvReminderSetting.Columns["ReminderDescription"].ReadOnly = true;
           dgvReminderSetting.Columns["ColorColumn"].ReadOnly = true;
           dgvReminderSetting.Columns["ReminderSettingId"].Visible = false;
       }

这是我在frm_load中的代码

这里没有在datagridview单元格中显示backcolor



可以从dialogcolor中保存数据库中的颜色然后绑定到c中的gridview#



先谢谢

this is my code in frm_load
here not showing backcolor in datagridview cells

it is possible to save color in database from dialogcolor then bind to gridview in c#

Thanks in Advance

推荐答案



使用网格的CellFormatting evetn;



Hi,
Use CellFormatting evetn of grid like;

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.Value != null && e.Value.Equals("something"))
            {
               e.CellStyle.BackColor = Color.Yellow;
               e.CellStyle.SelectionBackColor = Color.Yellow;
               e.CellStyle.SelectionForeColor = Color.Black;
            }
            else if (e.Value != null && e.Value.Equals("else"))
            {
               e.CellStyle.BackColor = Color.Red;
               e.CellStyle.SelectionBackColor = Color.Red;
            }
        }


这篇关于如何在Datagridview行单元格中设置Backcolor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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