Public Class Form1
Inherits System.Windows.Forms.Form
'variables for brush colors
Private asqn As Brush
Private bsqn As Brush
Private fsqn As Brush
Private gsqn As Brush
Private ops As Brush
Private spsqn As Brush
Private other As Brush
Private vor As Brush
Private hitRow As Integer
Private toolTip1 As System.Windows.Forms.ToolTip
#Region " Windows Form Designer generated code "
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Brush colors
Me.asqn = Brushes.DeepPink
Me.bsqn = Brushes.DarkOrange
Me.fsqn = Brushes.DarkSeaGreen
Me.gsqn = Brushes.Green
Me.ops = Brushes.Pink
Me.spsqn = Brushes.Brown
Me.vor = Brushes.Red
'fill datagrid
Me.SqlDataAdapter1.Fill(Me.DataSet11)
'create datagridstyle and set to sql table
Dim tableStyle As New DataGridTableStyle
tableStyle.MappingName = "VehJul"
'create columns for datagrid using class
Dim column As New FormattableTextBoxColumn
column.MappingName = "AssetID"
column.HeaderText = "ID"
column.Width = 40
AddHandler column.SetCellFormat, AddressOf FormatGridRow
tableStyle.GridColumnStyles.Add(column)
column = New FormattableTextBoxColumn
column.MappingName = "Asset"
column.HeaderText = "Asset"
column.Width = 130
AddHandler column.SetCellFormat, AddressOf FormatGridRow
tableStyle.GridColumnStyles.Add(column)
column = New FormattableTextBoxColumn
column.MappingName = "Notes"
column.HeaderText = "Notes"
AddHandler column.SetCellFormat, AddressOf FormatGridRow
tableStyle.GridColumnStyles.Add(column)
column = New FormattableTextBoxColumn
column.MappingName = "1"
column.HeaderText = "1"
column.Width = 20
AddHandler column.SetCellFormat, AddressOf FormatGridRow
tableStyle.GridColumnStyles.Add(column)
column = New FormattableTextBoxColumn
column.MappingName = "2"
column.HeaderText = "2"
column.Width = 20
AddHandler column.SetCellFormat, AddressOf FormatGridRow
tableStyle.GridColumnStyles.Add(column)
column = New FormattableTextBoxColumn
column.MappingName = "3"
column.HeaderText = "3"
column.Width = 20
AddHandler column.SetCellFormat, AddressOf FormatGridRow
tableStyle.GridColumnStyles.Add(column)
column = New FormattableTextBoxColumn
column.MappingName = "4"
column.HeaderText = "4"
column.Width = 20
AddHandler column.SetCellFormat, AddressOf FormatGridRow
tableStyle.GridColumnStyles.Add(column)
'column = New FormattableTextBoxColumn
column.MappingName = "5"
column.HeaderText = "5"
column.Width = 20
AddHandler column.SetCellFormat, AddressOf FormatGridRow
tableStyle.GridColumnStyles.Add(column)
column = New FormattableTextBoxColumn
column.MappingName = "6"
column.HeaderText = "6"
column.Width = 20
AddHandler column.SetCellFormat, AddressOf FormatGridRow
tableStyle.GridColumnStyles.Add(column)
'Add to the datagrid
Me.DataGrid1.TableStyles.Add(tableStyle)
End Sub
#Region "columnstyle event handlers"
Private Sub FormatGridRow(ByVal sender As Object, ByVal e As DataGridFormatCellEventArgs)
' Conditionally set properties in e depending upon e.Row and e.Col.
Dim discontinued As Boolean = CBool(IIf(e.Column <> 0, Me.DataGrid1(e.Row, 0), e.CurrentCellValue)) 'TODO: For performance reasons this should be changed to nested IF statements
Dim a As String
a = e.CurrentCellValue
If a = "A" Then e.BackBrush = asqn
If a = "B" Then e.BackBrush = bsqn
If a = "F" Then e.BackBrush = fsqn
If a = "G" Then e.BackBrush = gsqn
If a = "O" Then e.BackBrush = ops
If a = "S" Then e.BackBrush = spsqn
If a = "V" Then e.BackBrush = vor
If a = "N" Then e.BackBrush = other
End Sub
#End Region
#Region "Helper Methods"
' Forces a repaint of given row.
Private Sub RefreshRow(ByVal row As Integer)
Dim rect As Rectangle = Me.DataGrid1.GetCellBounds(row, 0)
rect = New Rectangle(rect.Right, rect.Top, Me.DataGrid1.Width, rect.Height)
Me.DataGrid1.Invalidate(rect)
End Sub 'RefreshRow
' Look back up in the project path for file...
Private Function GetPathTo(ByVal name As String) As String
Dim i As Integer
For i = 0 To 3
If System.IO.File.Exists(name) Then
Exit For
End If
name = "..\" + name
Next i
Return name
End Function 'GetPathTo
#End Region
End Class