5
Reply

Datagridview painting

David Smith

David Smith

Feb 23 2010 2:10 AM
4.2k
Hi Added this peace of code, Im trying to to just click any cell ,row  or column during runtime and highlight with a color.

Instead it highlights everything instead. I think is because of the loop. let me try something else.  If you have any ideas please dont hesitate


            try
            {
                colorDialog1.ShowDialog();

                for (int i = 0; i < dataGridView2.Rows.Count; i++)
                {


                    /*if (Convert.ToUInt32(dataGridView2.Rows[i].Cells[9].Value) == 0)
                    {
                        this.dataGridView2.Rows[i].DefaultCellStyle.BackColor = Color.Red;
                    }*/
                    if (Convert.ToUInt32(dataGridView2.Rows[i].Cells[i].Value) == 0)
                    {

                        this.dataGridView2.Rows[i].DefaultCellStyle.BackColor = colorDialog1.Color;
                    }

                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

Answers (5)