Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
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.
C#
{           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
Updated 9-Jan-13 2:57am
v10
Comments
Herman<T>.Instance 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

Hi,
Use CellFormatting evetn of grid like;

C#
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;
            }
        }
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900