473,320 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

change color of row in a Datagrid view.

Hi all,

I am newbie in c# and i have a question regarding DataGridView
I have a Table with 3 Columns
(0)IdLeggiSeriale <Is Primary key>
(1)ValoreSeriale <Is Integer>
(2)DataAcquisizione <Is DateTime>
I will like to change the color of each row that
in the in column(1) "ValoreSeriale" the Value is greater than 50.
private void dataGridView1_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{

if
(dataGridView1.Columns[e.ColumnIndex].Name.Equals("ValoreSeriale"))
{
Int32 intValue;
if (Int32.TryParse((String)e.Value, out intValue) &&
(intValue 50))
{
e.CellStyle.BackColor = Color.Yellow;
e.CellStyle.SelectionBackColor = Color.DarkRed;
}
}
}

In the Above code i only change the color a singular cell.

How can i change all the row.

Thanks
Marco
Jul 4 '07 #1
3 14989
hi

u could use below function and call this function OnRowCreated=HighlightRow
in your grid view

protected void HighlightRow(Object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

//find your control here whether its a textbox or label

Label lblValoreSeriale= (Label)e.Row.FindControl("lblValoreSeriale");

if(lblValorSeriale != null)

{

ifConvert.ToInt32((lblValoreSeriale.Text) 50)

e.Row.BackColor = System.Drawing.Color.Aqua;

}

}

}

hope this helps
"kjqua" <kj***@pippo.itwrote in message
news:eZ**************@TK2MSFTNGP02.phx.gbl...
Hi all,

I am newbie in c# and i have a question regarding DataGridView
I have a Table with 3 Columns
(0)IdLeggiSeriale <Is Primary key>
(1)ValoreSeriale <Is Integer>
(2)DataAcquisizione <Is DateTime>
I will like to change the color of each row that
in the in column(1) "ValoreSeriale" the Value is greater than 50.
private void dataGridView1_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{

if
(dataGridView1.Columns[e.ColumnIndex].Name.Equals("ValoreSeriale"))
{
Int32 intValue;
if (Int32.TryParse((String)e.Value, out intValue) &&
(intValue 50))
{
e.CellStyle.BackColor = Color.Yellow;
e.CellStyle.SelectionBackColor = Color.DarkRed;
}
}
}

In the Above code i only change the color a singular cell.

How can i change all the row.

Thanks
Marco

Jul 4 '07 #2
Hi Puja,

I try your function but i have this error:

The type or namespace name 'GridViewRowEventArgs' could not be found
(are you missing a using directive or an assembly reference?)

The dataGridView1 is on the form.

LeggiSeriale.mdf is the name of my database

Seriale_1 Is the name of the Table
IdLeggiSeriale is the name of the 1 column in the Table Seriale_1
ValoreSeriale is the name of the 2 column in the Table Seriale_1
DataAcquisizione is the name of the 3 column in the Table Seriale_1

thanks
Puja ha scritto:
hi

u could use below function and call this function OnRowCreated=HighlightRow
in your grid view

protected void HighlightRow(Object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

//find your control here whether its a textbox or label

Label lblValoreSeriale= (Label)e.Row.FindControl("lblValoreSeriale");

if(lblValorSeriale != null)

{

ifConvert.ToInt32((lblValoreSeriale.Text) 50)

e.Row.BackColor = System.Drawing.Color.Aqua;

}

}

}

hope this helps
"kjqua" <kj***@pippo.itwrote in message
news:eZ**************@TK2MSFTNGP02.phx.gbl...
>Hi all,

I am newbie in c# and i have a question regarding DataGridView
I have a Table with 3 Columns
(0)IdLeggiSeriale <Is Primary key>
(1)ValoreSeriale <Is Integer>
(2)DataAcquisizione <Is DateTime>
I will like to change the color of each row that
in the in column(1) "ValoreSeriale" the Value is greater than 50.
private void dataGridView1_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{

if
(dataGridView1.Columns[e.ColumnIndex].Name.Equals("ValoreSeriale"))
{
Int32 intValue;
if (Int32.TryParse((String)e.Value, out intValue) &&
(intValue 50))
{
e.CellStyle.BackColor = Color.Yellow;
e.CellStyle.SelectionBackColor = Color.DarkRed;
}
}
}

In the Above code i only change the color a singular cell.

How can i change all the row.

Thanks
Marco

Jul 4 '07 #3
are u using dot net version 2.0? i am using same code and it works fine.

"kjqua" <kj***@pippo.itwrote in message
news:eJ**************@TK2MSFTNGP02.phx.gbl...
Hi Puja,

I try your function but i have this error:

The type or namespace name 'GridViewRowEventArgs' could not be found (are
you missing a using directive or an assembly reference?)

The dataGridView1 is on the form.

LeggiSeriale.mdf is the name of my database

Seriale_1 Is the name of the Table
IdLeggiSeriale is the name of the 1 column in the Table Seriale_1
ValoreSeriale is the name of the 2 column in the Table Seriale_1
DataAcquisizione is the name of the 3 column in the Table Seriale_1

thanks
Puja ha scritto:
>hi

u could use below function and call this function
OnRowCreated=HighlightRow in your grid view

protected void HighlightRow(Object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

//find your control here whether its a textbox or label

Label lblValoreSeriale= (Label)e.Row.FindControl("lblValoreSeriale");

if(lblValorSeriale != null)

{

ifConvert.ToInt32((lblValoreSeriale.Text) 50)

e.Row.BackColor = System.Drawing.Color.Aqua;

}

}

}

hope this helps
"kjqua" <kj***@pippo.itwrote in message
news:eZ**************@TK2MSFTNGP02.phx.gbl...
>>Hi all,

I am newbie in c# and i have a question regarding DataGridView
I have a Table with 3 Columns
(0)IdLeggiSeriale <Is Primary key>
(1)ValoreSeriale <Is Integer>
(2)DataAcquisizione <Is DateTime>
I will like to change the color of each row that
in the in column(1) "ValoreSeriale" the Value is greater than 50.
private void dataGridView1_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{

if
(dataGridView1.Columns[e.ColumnIndex].Name.Equals("ValoreSeriale"))
{
Int32 intValue;
if (Int32.TryParse((String)e.Value, out intValue) &&
(intValue 50))
{
e.CellStyle.BackColor = Color.Yellow;
e.CellStyle.SelectionBackColor = Color.DarkRed;
}
}
}

In the Above code i only change the color a singular cell.

How can i change all the row.

Thanks
Marco
Jul 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andy Eshtry | last post by:
Hello Dear Professionals: Based on this document: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskcreatingwebservercontroltemplatesdynamically.asp or this...
6
by: Alpha | last post by:
I have several textboxes that I need to chang the text when the selection row is changed in a datagrid. I have the following code. This textbox displayes the initial selection but when I click on...
3
by: Richard | last post by:
I'm trying to change a value of a cell based on another before the grid is displayed. I'm using the ItemDataBound event like this for a simple test: Select Case e.Item.ItemType Case...
1
by: troyblakely | last post by:
I am having trouble sorting a datagrid. I have read numerous posts on this and other lists, and tried most of the suggestions, but none of them have worked for me yet. I populate a dataset from two...
5
by: HS1 | last post by:
Hello I have a datagrid to show data for a database table using "seclect * from tablename" The datagrid works OK. However, I want to change the name of the fields in the database to other...
2
by: CharlesA | last post by:
Hi folks, first off, I'm using Framework vs 1.1 with ASP.net and C# I'm trying to extend the System.Web.UI.Webcontrols.DataGrid, and the only thing I want to extend is the Render method (in...
2
by: simonyong | last post by:
hello, anyone.. im newbie to asp.net my problem is : My task is related to view all data from a table called "employee " i had create a datagrid where called data from database and...
3
by: simonyong | last post by:
Im a newbie to asp.net, i hav a bit dilemma when thinking about how i should let it work.. My task as below: My task is related to view all data from a table called "employee " i had create a...
1
by: simonyong | last post by:
Hi, I have a hyperlinkbutton in my datagrid Initially, I set the text of the hyperlink button as "show" once user click it, i want it to change into "view more detail" I tried to change...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.