Click here to Skip to main content
12,635,011 members (29,687 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# Windows Application
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;               

            dgvReminderSetting.Columns["ReminderDescription"].ReadOnly = true;
            dgvReminderSetting.Columns["ColorColumn"].ReadOnly = true;
            dgvReminderSetting.Columns["ReminderSettingId"].Visible = false;
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
Posted 9-Jan-13 0:16am
Updated 9-Jan-13 3:57am
digimanus 9-Jan-13 5:31am
is this asp? you state: this is my code in page_load
phoolchand yadav 9-Jan-13 5:54am
windows application sorry it is frm_load

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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;

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100