[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Highlighting rows in a DataGrid

Posted on 2005-04-29
8
Medium Priority
?
317 Views
Last Modified: 2010-04-17
How can I highlight certain rows in a DataGrid in Visual Basic .NET 2003?

Thanks
0
Comment
Question by:SETP
7 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 13893633
Hi SETP,

In the ItemDataBound event of the grid, you can test whether the row should be highlighted and alter the backcolor and/or forecolor of the cells as appropriate.

Tim Cottee
0
 
LVL 2

Expert Comment

by:jong3
ID: 13894576
A DataGrid is basically a dynamically created table.  If you look at the code once your page is generated, you will see a bunch of table tags (TD, TR, etc..)

In order to set the color of the row in a table, you need to do it before the code is generated.  This can be done in the "ItemDataBound" event of the datagrid.

Inside your ItemDataBound event, add something like the following:

   If e.Item.Cells(0).Text = MYCONDITION Then
         e.Item.BackColor = System.Drawing.Color.Red   //sets the bg color
         e.Item.Font.Bold = True                                    //sets the font to bold
   End If

I hope this helps.
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 1500 total points
ID: 13895390
Windows or Web ?

the 2 previous comments apply to Web datagrid.

If you meant Windows, have a look at http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.aspx#q745q
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:SETP
ID: 13907500
Sorry - I'm using Windows Forms, not Web Forms.

I check out that link. Is there no simpler way of doing it? I can't believe Microsoft didn't add a simple way to change the background color of a row!
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 13907759
The DataGrid has never been the best Microsoft control!
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 14187792
recommandation: points to emoreau
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question