[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Highlight Datagrid (Winforms) row

Posted on 2006-07-06
8
Medium Priority
?
552 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
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.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

649 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