Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
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 8-Jan-13 23:16pm
Edited 9-Jan-13 2:57am
digimanus at 9-Jan-13 5:31am
is this asp? you state: this is my code in page_load
phoolchand yadav at 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
Your Filters
0 sanket saxena 355
1 Abhinav S 303
2 Sergey Alexandrovich Kryukov 299
3 OriginalGriff 225
4 thatraja 220
0 Sergey Alexandrovich Kryukov 8,497
1 OriginalGriff 4,850
2 Peter Leow 3,839
3 Maciej Los 3,535
4 Er. Puneet Goel 3,107

Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid