473,748 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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)IdLeggiSeria le <Is Primary key>
(1)ValoreSerial e <Is Integer>
(2)DataAcquisiz ione <Is DateTime>
I will like to change the color of each row that
in the in column(1) "ValoreSeri ale" the Value is greater than 50.
private void dataGridView1_C ellFormatting(o bject sender,
DataGridViewCel lFormattingEven tArgs e)
{

if
(dataGridView1. Columns[e.ColumnIndex].Name.Equals("V aloreSeriale"))
{
Int32 intValue;
if (Int32.TryParse ((String)e.Valu e, out intValue) &&
(intValue 50))
{
e.CellStyle.Bac kColor = Color.Yellow;
e.CellStyle.Sel ectionBackColor = 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 15022
hi

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

protected void HighlightRow(Ob ject sender, GridViewRowEven tArgs e)

{

if (e.Row.RowType == DataControlRowT ype.DataRow)

{

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

Label lblValoreSerial e= (Label)e.Row.Fi ndControl("lblV aloreSeriale");

if(lblValorSeri ale != null)

{

ifConvert.ToInt 32((lblValoreSe riale.Text) 50)

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

}

}

}

hope this helps
"kjqua" <kj***@pippo.it wrote in message
news:eZ******** ******@TK2MSFTN GP02.phx.gbl...
Hi all,

I am newbie in c# and i have a question regarding DataGridView
I have a Table with 3 Columns
(0)IdLeggiSeria le <Is Primary key>
(1)ValoreSerial e <Is Integer>
(2)DataAcquisiz ione <Is DateTime>
I will like to change the color of each row that
in the in column(1) "ValoreSeri ale" the Value is greater than 50.
private void dataGridView1_C ellFormatting(o bject sender,
DataGridViewCel lFormattingEven tArgs e)
{

if
(dataGridView1. Columns[e.ColumnIndex].Name.Equals("V aloreSeriale"))
{
Int32 intValue;
if (Int32.TryParse ((String)e.Valu e, out intValue) &&
(intValue 50))
{
e.CellStyle.Bac kColor = Color.Yellow;
e.CellStyle.Sel ectionBackColor = 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 'GridViewRowEve ntArgs' could not be found
(are you missing a using directive or an assembly reference?)

The dataGridView1 is on the form.

LeggiSeriale.md f 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
DataAcquisizion e 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=Hi ghlightRow
in your grid view

protected void HighlightRow(Ob ject sender, GridViewRowEven tArgs e)

{

if (e.Row.RowType == DataControlRowT ype.DataRow)

{

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

Label lblValoreSerial e= (Label)e.Row.Fi ndControl("lblV aloreSeriale");

if(lblValorSeri ale != null)

{

ifConvert.ToInt 32((lblValoreSe riale.Text) 50)

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

}

}

}

hope this helps
"kjqua" <kj***@pippo.it wrote in message
news:eZ******** ******@TK2MSFTN GP02.phx.gbl...
>Hi all,

I am newbie in c# and i have a question regarding DataGridView
I have a Table with 3 Columns
(0)IdLeggiSeri ale <Is Primary key>
(1)ValoreSeria le <Is Integer>
(2)DataAcquisi zione <Is DateTime>
I will like to change the color of each row that
in the in column(1) "ValoreSeri ale" the Value is greater than 50.
private void dataGridView1_C ellFormatting(o bject sender,
DataGridViewCe llFormattingEve ntArgs e)
{

if
(dataGridView1 .Columns[e.ColumnIndex].Name.Equals("V aloreSeriale"))
{
Int32 intValue;
if (Int32.TryParse ((String)e.Valu e, out intValue) &&
(intValue 50))
{
e.CellStyle.Bac kColor = Color.Yellow;
e.CellStyle.Sel ectionBackColor = 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.it wrote in message
news:eJ******** ******@TK2MSFTN GP02.phx.gbl...
Hi Puja,

I try your function but i have this error:

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

The dataGridView1 is on the form.

LeggiSeriale.md f 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
DataAcquisizion e 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=H ighlightRow in your grid view

protected void HighlightRow(Ob ject sender, GridViewRowEven tArgs e)

{

if (e.Row.RowType == DataControlRowT ype.DataRow)

{

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

Label lblValoreSerial e= (Label)e.Row.Fi ndControl("lblV aloreSeriale");

if(lblValorSer iale != null)

{

ifConvert.ToIn t32((lblValoreS eriale.Text) 50)

e.Row.BackColo r = System.Drawing. Color.Aqua;

}

}

}

hope this helps
"kjqua" <kj***@pippo.it wrote in message
news:eZ******* *******@TK2MSFT NGP02.phx.gbl.. .
>>Hi all,

I am newbie in c# and i have a question regarding DataGridView
I have a Table with 3 Columns
(0)IdLeggiSer iale <Is Primary key>
(1)ValoreSeri ale <Is Integer>
(2)DataAcquis izione <Is DateTime>
I will like to change the color of each row that
in the in column(1) "ValoreSeri ale" the Value is greater than 50.
private void dataGridView1_C ellFormatting(o bject sender,
DataGridViewC ellFormattingEv entArgs e)
{

if
(dataGridView 1.Columns[e.ColumnIndex].Name.Equals("V aloreSeriale"))
{
Int32 intValue;
if (Int32.TryParse ((String)e.Valu e, out intValue) &&
(intValue 50))
{
e.CellStyle.Bac kColor = Color.Yellow;
e.CellStyle.Sel ectionBackColor = 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
999
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 http://www.dnzone.com/ShowDetail.asp?NewsId=599 I want to create 3 template column in datagrid dynamically while the template columns contains image buttons for add, edit and delete. As you can see, I can figure out the commandname inside the...
6
3337
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 different rows in the datagrid, the textbox content doesn't change to reflect the change. How can I address this? Also, If the user change the text in the textbox then how do I refesh the display in the datagrid to reflect the changes? ...
3
2443
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 ListItemType.Item, ListItemType.AlternatingItem If e.Item.Cells(7).Text = String.Empty Then e.Item.Cells(7).Text = "hello" End If End Select
1
1771
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 queries, then I want to sort the data and bind it to a datagrid. Regardless of what I have tried, the datagrid is populated with the unsorted data. Any assistance you have would be appreciated. I have attempted the sort using the dataview.sort...
5
4241
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 name in DataGrid. For example, a field name in database is "FName" will be shown in dataGrid as "First Name". Could you please tell me how to do that
2
1244
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 order to add <thead> and <tbody> elements) so far so good I've placed this code into another project called CustomControls with a
2
1614
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 successfully display in a datagrid.. each employee will hav their own personnel_number and direct_manager_personnel_number which refer to who is his/her direct boss... eg.
3
1675
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 datagrid where called data from database and successfully display in a datagrid.. each employee will hav their own personnel_number and direct_manager_personnel_number which refer to who is his/her direct boss... eg. CEO hav personnel_number= 2...
1
2223
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 as below but it lose its hyperlink function and just as a text only
0
9561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8252
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.