ListView Gridline color
-
-
I have one listview which is owner drawn. I have to change the grid line color. I tried this by making GridLines = false for listview and Draw the gridlines programatically. But if there are 100 items its flickering and a lot of painting issues Sibi
-
Where do you put the painting code? Paste your code, or it's hard to resolve it.
--------------------------------- Believe what you saw!
/// /// /// /// /// private void TreeListView_DrawItem( object sender, DrawListViewItemEventArgs e ) { Graphics g = e.Graphics; TreeListViewItem item = ( TreeListViewItem )e.Item; item.UpdateBounds(); this.DrawExpandMarker( g, item ); this.DrawCheckBox( g, item ); StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Center; sf.FormatFlags = StringFormatFlags.NoWrap; SolidBrush foreBrush = new SolidBrush( this.ForeColor ); if( this.changeSelectionForeColor == true ) { foreBrush = new SolidBrush( item.ForeColor ); } SolidBrush fillBrush = new SolidBrush( item.BackColor ); Rectangle fillRect = e.Bounds; fillRect.X = item.TextBounds.X; fillRect.Width -= fillRect.X; fillRect.Height -= 1; if( item.Selected == true && item.ReadOnly == false && item.IsDummy == false ) { selectedItem = item; item.IsInvalidated = false; foreBrush = new SolidBrush( SystemColors.HighlightText ); if( this.changeSelectionForeColor == true ) { foreBrush = new SolidBrush( item.ForeColor ); } fillBrush = new SolidBrush( SystemColors.Highlight ); } g.FillRectangle( fillBrush, fillRect ); string text = this.GetAdjustedString( g, e.Item.Text, item.TextBounds, this.Font ); if( item.ReadOnly == false ) { g.DrawString( text, this.Font, foreBrush, item.TextBounds, sf ); } if( item.IsButtonNeeded == true ) { SolidBrush buttonBrush = new SolidBrush( this.Parent.BackColor ); Rectangle buttonRect = item.ButtonBounds; g.FillRectangle( buttonBrush, buttonRect ); Border3DStyle border = item.IsButtonPressed ? Border3DStyle.Adjust : Border3DStyle.RaisedInner; ControlPaint.DrawBorder3D( g, buttonRect, border ); sf.Alignment = StringAlignment.Center; this.Draw3DText( g, buttonRect, item.ButtonText, sf, item.IsButtonPressed );