Posted on 1 Comment

Project: Customizing the Windows Forms DataGrid

Learning how to change the display of tabular data on a windows form datagrid. (Apparently not as simple as bgcolor = … )

Requirements:
The form will need to adjust visually according to the status of the row. For example, changing to gray when the row is selected and a different colour to indicate focus.

1 thought on “Project: Customizing the Windows Forms DataGrid

  1. Basic steps to creating a customized datagrid in vb.net.

    Note: This is just the main bits, there are little pieces that need to be coded here and there to complete it.

    1) Declare your variables
    Private disabledBackBrush As Brush
    Private disabledTextBrush As Brush
    Private currentRowFont As Font
    Private currentRowBackBrush As Brush
    *************************
    2) Give your brushes values
    Me.disabledBackBrush = New SolidBrush(SystemColors.InactiveCaptionText)
    Me.disabledTextBrush = New SolidBrush(SystemColors.GrayText)
    Me.currentRowFont = New Font(Me.DataGrid1.Font.Name, Me.DataGrid1.Font.Size, FontStyle.Bold)
    Me.currentRowBackBrush = Brushes.Pink
    ******************************
    3) Have it activate the colours depending on when you want it to change from the basic settings.
    If e.Column > 0 AndAlso Me.DataGrid1(e.Row, 7) = 0 Then ‘discontinued?
    e.BackBrush = Me.currentRowBackBrush
    e.TextFont = Me.currentRowFont
    ElseIf e.Column > 0 AndAlso e.Row = Me.DataGrid1.CurrentRowIndex Then ‘currentrow?
    e.BackBrush = Me.disabledBackBrush
    e.ForeBrush = Me.disabledTextBrush
    End If

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.