Solved

Highlight Datagrid (Winforms) row

Posted on 2006-07-06
8
544 Views
Last Modified: 2010-05-18
I'm using VS2003, C#. I have a windows form with a datagrid and I would like to highlight the whole row based on the data on the first column. Thanks in advance.
0
Comment
Question by:IceMan713
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
8 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17051478
Try this:

   if (this.dataGrid1[0, 0].ToString() == "Test")
      this.dataGrid1.Select(0);

 - dataGrid1[0, 0] = row #1, column #1
 - Select(0) selects row #1.

Bob
0
 
LVL 1

Author Comment

by:IceMan713
ID: 17053374
that will just select the row, I want to highlight multiple rows (not select), so that I can click on any cell and the highlight won't change.

Thanks.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17054564
Aaah, yes, you want to change the BackColor of the cells based on the value from another column, right?

Bob
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:IceMan713
ID: 17058145
yup
0
 
LVL 1

Author Comment

by:IceMan713
ID: 17058362
I got it!  Here's how I did it...

protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
                  {
                        // the idea is to conditionally set the foreBrush and/or backbrush
                        // depending upon some crireria on the cell value
                        // Here, we color the cell if the first column is True
                        try
                        {
                              
                              DataTable dtPaint;

                              DataRow drPaint;

                              dtPaint =  (DataTable)this.DataGridTableStyle.DataGrid.DataSource;

                              drPaint = dtPaint.Rows[rowNum];
                              


                              //If true then highlight
                              bool blnHighlight = Convert.ToBoolean (drPaint["HighlightRow"].ToString());


                              if ( blnHighlight)

                              {

                                    backBrush = new System.Drawing.Drawing2D.LinearGradientBrush(bounds,

                                          Color.IndianRed,

                                          Color.IndianRed,

                                          System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);

                                    foreBrush = new SolidBrush(Color.White);

                              }


                        }
                        catch(Exception ex)
                        {
                              string x = ex.Message;
                        }
                        finally
                        {
                              // make sure the base class gets called to do the drawing with
                              // the possibly changed brushes
                              base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
                        }
                  }
0
 
LVL 1

Author Comment

by:IceMan713
ID: 17058375
how can I request for a refund?
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 17306614
PAQ / Refund
ee ai construct, community support moderator
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

689 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