PC Review


Reply
Thread Tools Rate Thread

[c# 2008] color rows of datagridview

 
 
Christian
Guest
Posts: n/a
 
      9th May 2008
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
 
Reply With Quote
 
 
 
 
Ignacio Machin ( .NET/ C# MVP )
Guest
Posts: n/a
 
      9th May 2008
On May 9, 5:01*am, 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
 
Reply With Quote
 
 
 
 
Christian
Guest
Posts: n/a
 
      12th May 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);
}
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;
}
thanks
 
Reply With Quote
 
Joachim Van den Bogaert
Guest
Posts: n/a
 
      21st May 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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change font color for certain rows in DataGridview Elmo Watson Microsoft Dot NET Framework Forms 3 25th Nov 2010 01:06 PM
color transition (color changes from dark color to light color) color transition Microsoft Powerpoint 2 21st Nov 2009 01:21 PM
DataGridView with rows in plus rows enrico Microsoft Dot NET Framework Forms 1 27th Feb 2009 08:00 PM
dataGridView.Rows.Count and datagridview.RowCount SePp Microsoft C# .NET 1 15th Jan 2008 11:27 AM
DataGridView: Change the color of edited rows RSH Microsoft C# .NET 0 29th Dec 2005 08:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:42 PM.