Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows Application
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;
        }
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
v10
Comments
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
good
Please Sign up or sign in to vote.

Solution 1

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

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,935
1 OriginalGriff 6,987
2 CPallini 5,845
3 George Jonsson 4,015
4 Gihan Liyanage 3,266


Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2014
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