Visual Basic - Add line(s) on individual rows in datagridview - Flickering
I have a datagridview in my application (at this moment Visual Basic 2008, but in the near future Visual Basic 2010) and I want to create line(s) in individual rows.
At this moment I use the following code:
Private Sub datagridview1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles datagridview1.CellPainting Dim row As DataGridViewRow = datagridview1.Rows(e.RowIndex) Dim BackColorBrush As New SolidBrush(e.CellStyle.BackColor) Dim GridBrush As New SolidBrush(Me.datagridview1.GridColor) Dim GridLinePen As New Pen(GridBrush) ' -- Erase the cell e.Graphics.FillRectangle(BackColorBrush, e.CellBounds) Dim ProgressBarBrush As New SolidBrush(Color.Black) Dim CellProgressBarRect As New Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Width, 2) e.Graphics.FillRectangle(ProgressBarBrush, CellProgressBarRect) e.Handled = True Dim style As New DataGridViewCellStyle style.Font = New Font(datagridview1.Font, FontStyle.Bold) datagridview1.Rows(e.RowIndex).DefaultCellStyle = styleEnd Sub
Thank you for your answer! Can you be a little bit more specific?
What do I have to do with my cellpainting code?
The datagridview is filled by a sql query (fill a datatable). I added columns manually and connect the datagridview to a datatable (datasource = datatable) in the form_load.
Rgonzo1971
Hi,
You can try SuspendLayout () before initializing your form and ResumeLayout () after initialization. Sometimes this doesn't work. When it doesn't, you can try using the Win32 functions:
Outside of your method:
using Microsoft.Win32;
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
private const int WM_SETREDRAW = 11;
This could help
Open in new window