Hi,
i create aprogram that load a table from Access DB.
i want color rows with different color but when i run the program and
i load the datagridview the first time, the rows are white!
only when i insert a new record the rows change color, why?
thanks to all!
bye

Re: color rows of datagridview by Ignacio

Ignacio
Fri May 09 14:17:24 CDT 2008

On May 9, 5:01=A0am, Christian <christian.per...@gmail.com> wrote:
> Hi,
> i create aprogram that load a table from Access DB.
> i want color rows with different color but when i run the program and
> i load the datagridview the first time, the rows are white!
> only when i insert a new record the rows change color, why?
> thanks to all!
> bye

how are you assigning it?
post some code

Re: color rows of datagridview by Christian

Christian
Mon May 12 08:22:20 CDT 2008

ok....
i create a Method to Load the datagridview....
[code]
public void Visualizza()
{
string querySelect = "select * from Tabella1";
try
{
OleDbCommand command = new OleDbCommand();
DataTable dt = null;
dataGridView1.DataSource = null;
command.Connection = null;
OleDbDataAdapter DAdapter = null;
dataGridView1.Columns.Clear();
command.CommandText = querySelect;

command.Connection = cnn;
dt = new DataTable();
DAdapter = new OleDbDataAdapter(command);
DAdapter.Fill(dt);
dataGridView1.DataSource = dt;

dataGridView1.AllowUserToAddRows = false;
dataGridView1.ReadOnly = true;

ImpostaLarghezzaColonne();

ColoraRighe(dataGridView1,dt);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
[/code]
in the Method Called "ColoraRighe" i try to colors the rows
[code]
public void ColoraRighe(DataGridView da,DataTable dt)
{
if (da.RowCount != 0)
{
foreach (DataGridViewRow row in da.Rows)
{
if (row.Cells[1].Value.ToString() == "Working")
row.DefaultCellStyle.BackColor = Color.LightGoldenrodYellow;
if (row.Cells[1].Value.ToString() == "Si")
row.DefaultCellStyle.BackColor = Color.LightGreen;
if (row.Cells[1].Value.ToString() == "No")
row.DefaultCellStyle.BackColor = Color.Red;
}
}
dataGridView1.DataSource = dt;
}
[/code]

thanks

Re: color rows of datagridview by Joachim

Joachim
Wed May 21 02:35:58 CDT 2008

Hi Christian,

you will need the
System.Windows.Forms.DataGridViewCellFormattingEventHandler to do
this.

Here is an example:

http://msdn.microsoft.com/en-us/library/z1cc356h.aspx

Regards,

Joachim