I keep getting an invalid cast error on this line of code:
Dim gridCol As MyGridColumn = CType(dgt.GridC olumnStyles(hi. Column),
MyGridColumn)
I am trying to develop a sub that will change the colors on a cell that
is clicked on in a DataGrid control.
Here is the full code:
Private Sub PaintCell(ByVal sender As Object, ByVal e As
MouseEventArgs)
Try
Dim hi As DataGrid.HitTes tInfo
Dim grid As DataGrid = CType(sender, DataGrid)
hi = grid.HitTest(e. X, e.Y)
If hi.Type = DataGrid.HitTes tType.Cell Then
Dim dgt As DataGridTableSt yle =
dgvBranches.Tab leStyles(0)
Dim cm As CurrencyManager =
CType(Me.Bindin gContext(myData Set.Tables(0)), CurrencyManager )
Dim cellRect As Rectangle
cellRect = grid.GetCellBou nds(hi.Row, hi.Column)
Dim gridCol As MyGridColumn =
CType(dgt.GridC olumnStyles(hi. Column), MyGridColumn)
Dim g As Graphics = dgvBranches.Cre ateGraphics()
Dim fBrush As New SolidBrush(Colo r.Blue)
Dim bBrush As New SolidBrush(Colo r.Yellow)
gridCol.PaintCo l(g, cellRect, cm, hi.Row, bBrush,
fBrush, False)
End If
Catch ex As Exception
LogErrors(ex, "PaintCell" )
End Try
End Sub 'PaintCell
Any help would be appreciated. Thanks!
Dim gridCol As MyGridColumn = CType(dgt.GridC olumnStyles(hi. Column),
MyGridColumn)
I am trying to develop a sub that will change the colors on a cell that
is clicked on in a DataGrid control.
Here is the full code:
Private Sub PaintCell(ByVal sender As Object, ByVal e As
MouseEventArgs)
Try
Dim hi As DataGrid.HitTes tInfo
Dim grid As DataGrid = CType(sender, DataGrid)
hi = grid.HitTest(e. X, e.Y)
If hi.Type = DataGrid.HitTes tType.Cell Then
Dim dgt As DataGridTableSt yle =
dgvBranches.Tab leStyles(0)
Dim cm As CurrencyManager =
CType(Me.Bindin gContext(myData Set.Tables(0)), CurrencyManager )
Dim cellRect As Rectangle
cellRect = grid.GetCellBou nds(hi.Row, hi.Column)
Dim gridCol As MyGridColumn =
CType(dgt.GridC olumnStyles(hi. Column), MyGridColumn)
Dim g As Graphics = dgvBranches.Cre ateGraphics()
Dim fBrush As New SolidBrush(Colo r.Blue)
Dim bBrush As New SolidBrush(Colo r.Yellow)
gridCol.PaintCo l(g, cellRect, cm, hi.Row, bBrush,
fBrush, False)
End If
Catch ex As Exception
LogErrors(ex, "PaintCell" )
End Try
End Sub 'PaintCell
Any help would be appreciated. Thanks!
Comment