Shamil Salakhetdinov
shamil at smsconsulting.spb.ru
Wed Dec 1 05:25:15 CST 2010
Hi Gustav -- Thank you for your sample code. I have to simulate hierarchical GridView (just one level) using DataGridView (I do not use third-party controls - that's my customer requirement). I do use RowPostPaint event to draw (+) - collpased , and (-) - expanded row sign on row header cells as well as on top-left cell - the latter is used to note/control collapsed/expanded datagridview rows on first level. All works fine except that I cannot find how to suppress/hide row selector arrow - when I use: - DataGridViewCell's .Style.BackColor to paint RowHeader cell's background - SelectionMode = CellSelect - ShowEditingIcon = False the record selector is still visible. I have to use custom color - Color.LightGray to paint it over. Thank you. -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: 1 ??????? 2010 ?. 12:05 To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] WinForms: What is the best event for custom drawing ona leftmost cell of DataGridView head Hi Shamil Don't know about a DataGridView but for a tab control I used DrawItem. Nothing fancy: <code> private void tabControlMail_DrawItem(object sender, DrawItemEventArgs e) { DrawTabColor(sender, e, Color.LightBlue, Color.Black, Color.BlueViolet, Color.Gray); } private void DrawTabColor(object sender, System.Windows.Forms.DrawItemEventArgs e, Color FocusedBackColor, Color FocusedForeColor, Color NonFocusedBackColor, Color NonFocusedForeColor) { Font myFont = new Font(e.Font, FontStyle.Regular); Brush backColorBrush; Brush foreColorBrush; StringFormat myFormat = new StringFormat(); TabControl tabControl = (TabControl)sender; Rectangle rectangle = new Rectangle(tabControl.Left , 15,tabControl.Width, tabControl.Height); backColorBrush = new System.Drawing.SolidBrush(Color.Linen); foreColorBrush = new System.Drawing.SolidBrush(Color.Gray); e.Graphics.FillRectangle(backColorBrush, rectangle); Console.WriteLine("s: " + this.tabControlMail.SelectedIndex.ToString ()+ ", e: " + e.Index.ToString()); if (e.Index == this.tabControlMail.SelectedIndex) { myFont = new Font(e.Font, FontStyle.Regular); backColorBrush = new System.Drawing.SolidBrush(FocusedBackColor); foreColorBrush = new System.Drawing.SolidBrush(FocusedForeColor); this.tabControlMail.TabPages[e.Index].BackColor = FocusedBackColor; string tabName = this.tabControlMail.TabPages[e.Index].Text; Rectangle rect = new Rectangle(e.Bounds.X + 4, e.Bounds.Y, e.Bounds.Width - 6, e.Bounds.Height); myFormat.Alignment = StringAlignment.Center; e.Graphics.FillRectangle(backColorBrush, rect); RectangleF r = new RectangleF(e.Bounds.X + 1, e.Bounds.Y + 4, e.Bounds.Width, e.Bounds.Height - 4); e.Graphics.DrawString(tabName, myFont, foreColorBrush, r, myFormat); } else { myFont = new Font(e.Font, FontStyle.Regular); backColorBrush = new System.Drawing.SolidBrush(NonFocusedBackColor); foreColorBrush = new System.Drawing.SolidBrush(NonFocusedForeColor); this.tabControlMail.TabPages[e.Index].BackColor = Color.Linen; // FocusedBackColor; string tabName = this.tabControlMail.TabPages[e.Index].Text; Rectangle rect = new Rectangle(e.Bounds.X + 1, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height + 1); myFormat.Alignment = StringAlignment.Center; e.Graphics.FillRectangle(backColorBrush, rect); RectangleF r = new RectangleF(e.Bounds.X, e.Bounds.Y + 4, e.Bounds.Width, e.Bounds.Height - 4); e.Graphics.DrawString(tabName, myFont, foreColorBrush, r, myFormat); } myFormat.Dispose(); myFont.Dispose(); backColorBrush.Dispose(); foreColorBrush.Dispose(); } </code> What are you trying to do? /gustav >>> shamil at smsconsulting.spb.ru 30-11-2010 19:44 >>> Hi All -- What is the best suitable event for custom drawing on a top/left cell of DataGridView ( .TopLeftHeaderCell)? .RowHeadersVisible = true Thank you. -- Shamil _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com