Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

Setting a style for a selected row in the DataGridView

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Simon Harvey - 12 Feb 2007 10:13 GMT
Hi

Can anyone tell me if there is a property for setting the default cell
style for a cell thats selected. I can see properties for the default
cell styling and alternate row styling but not for selected styles.

Am I missing something here? Do I have to write some custom formatting code?

Many thanks

Simon
ClayB - 12 Feb 2007 12:15 GMT
The selection settings is taken from the system setting (Advanced
Appearance tab of the Display settings om the Control Panel). One way
you can override this default behavior is to handle the CellPainting
event.

void dataGridView1_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
{

   if (e.RowIndex > -1 && e.ColumnIndex > -1)
   {
       e.Paint(e.ClipBounds, DataGridViewPaintParts.Background
                   | DataGridViewPaintParts.Border
                   | DataGridViewPaintParts.ContentBackground
                   | DataGridViewPaintParts.ContentForeground);
       if
(this.dataGridView1.SelectedCells.Contains(this.dataGridView1[e.ColumnIndex,
e.RowIndex]))
       {
           using (Brush b = new SolidBrush(Color.FromArgb(60,
Color.Red)))
           {
               e.Graphics.FillRectangle(b, e.CellBounds);
           }
       }
       e.Handled = true;
   }
}
==================
Clay Burch
Syncfusion, Inc.
Simon Harvey - 12 Feb 2007 19:42 GMT
Woah - holly cow - I was kinda hoping there was just a property that I
could use to set tyle stuff!

Or maybe using some "row selected" or "on selection" changed style event.

All that painting stuff seems hard! Is there something simpler?

Many thanks for your help

Simon
Tim Van Wassenhove - 12 Feb 2007 19:42 GMT
Simon Harvey schreef:
> Hi
>
[quoted text clipped - 4 lines]
> Am I missing something here? Do I have to write some custom formatting
> code?

There are DefaultCellStyle.SelectionForeColor and ..SelectionBackColor

Signature

Tim Van Wassenhove <url:http://www.timvw.be/>

Simon Harvey - 13 Feb 2007 15:25 GMT
YOU ARE A STALLION!

:-)

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.