Hi i want to be able to Paint cells, rows , and columns at runtime.
right now I have a sample code but its only painting to row 1 row. I want to be able to paint to all.
this is what i have so far. Is there away I can just pick the color from the colordialog box at run time and display to the grid instead
of me assigning the color by code.
if (checkBox1.Checked)
{
dataGridView2.Rows[1].DefaultCellStyle.BackColor = Color.White;
}
else
{
dataGridView2.Rows[1].DefaultCellStyle.BackColor = Color.Red;
}
Loading
David SmithPosted Feb 23, 2010, 2:09 AM
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);
}
David SmithPosted Feb 22, 2010, 12:21 PM
David SmithPosted Feb 22, 2010, 12:03 PM
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
if (Convert.ToInt16(dataGridView2.Rows[i].Cells[0].Value) == 0)
{
this.dataGridView2.Rows[i].DefaultCellStyle.BackColor = Color.Red;
}
}
the colors are not changing at all, i just dont understand whats going on, let me step through this code one more time.
David SmithPosted Feb 22, 2010, 11:57 AM
Im using dataGridView2 not dataGridView1
kiran kumarPosted Feb 22, 2010, 11:30 AM
and then pick "datagridcheckboxcolumn"
David SmithPosted Feb 22, 2010, 11:26 AM
are you talking about this code you paste earlier below
for(int i=0;i
if (Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value) == 0)
{
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red;
}
else
{
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Blue;
}
}
kiran kumarPosted Feb 22, 2010, 11:19 AM
just download the code which i gave and test it
kiran kumarPosted Feb 22, 2010, 11:17 AM
David SmithPosted Feb 22, 2010, 11:17 AM
the requirements are simply to highlight any cell, row, or column during run time , and then also give the user to unhighlight everything.
when I step through the code , it never broke in the loop at all, so thats reason why probably didnt not work
David SmithPosted Feb 22, 2010, 11:17 AM
the requirements are simply to highlight any cell, row, or column during run time , and then also give the user to unhighlight everything.
when I step through the code , it never broke in the loop at all, so thats reason why probably didnt not work
David SmithPosted Feb 22, 2010, 11:11 AM
David SmithPosted Feb 22, 2010, 11:02 AM
{
for(int i=0;i
if (Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value) == 0)
{
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red;
}
else
{
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Blue;
}
}
}
kiran kumarPosted Feb 22, 2010, 10:52 AM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace gridcolor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
for(int i=0;i
if (Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value) == 0)
{
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red;
}
}
}
}
}
MARK THE ANSWER IF IT HELPS YOU