|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Setting a style for a selected row in the DataGridViewHi
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 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 if| DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.ContentForeground); (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. 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 Simon Harvey schreef:
> Hi There are DefaultCellStyle.SelectionForeColor and ..SelectionBackColor> > 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?
Other interesting topics
GroupBox and/or Tab Control Font Colours
MDI app - don't load document twice toolstrip container backcolor and gradients - I want it to look like outlook 2003! OT: Crossword Puzzle Creator - .NET Source ClickOnce deployment, include font A Label control that its text can be selected with the mouse Need help on some PropertyGrid and PropertyGridView members Displaying a status image in a datagridview Assembly Version problems Generating 3D graphs in .Net 2.0 windows forms. |
|||||||||||||||||||||||