David Smith

David Smith

  • NA
  • 2k
  • 0

Datagridview painting

Feb 23 2010 2:10 AM
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)