A
Alan
I keep getting an invalid cast error on this line of code:
Dim gridCol As MyGridColumn = CType(dgt.GridColumnStyles(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.HitTestInfo
Dim grid As DataGrid = CType(sender, DataGrid)
hi = grid.HitTest(e.X, e.Y)
If hi.Type = DataGrid.HitTestType.Cell Then
Dim dgt As DataGridTableStyle =
dgvBranches.TableStyles(0)
Dim cm As CurrencyManager =
CType(Me.BindingContext(myDataSet.Tables(0)), CurrencyManager)
Dim cellRect As Rectangle
cellRect = grid.GetCellBounds(hi.Row, hi.Column)
Dim gridCol As MyGridColumn =
CType(dgt.GridColumnStyles(hi.Column), MyGridColumn)
Dim g As Graphics = dgvBranches.CreateGraphics()
Dim fBrush As New SolidBrush(Color.Blue)
Dim bBrush As New SolidBrush(Color.Yellow)
gridCol.PaintCol(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.GridColumnStyles(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.HitTestInfo
Dim grid As DataGrid = CType(sender, DataGrid)
hi = grid.HitTest(e.X, e.Y)
If hi.Type = DataGrid.HitTestType.Cell Then
Dim dgt As DataGridTableStyle =
dgvBranches.TableStyles(0)
Dim cm As CurrencyManager =
CType(Me.BindingContext(myDataSet.Tables(0)), CurrencyManager)
Dim cellRect As Rectangle
cellRect = grid.GetCellBounds(hi.Row, hi.Column)
Dim gridCol As MyGridColumn =
CType(dgt.GridColumnStyles(hi.Column), MyGridColumn)
Dim g As Graphics = dgvBranches.CreateGraphics()
Dim fBrush As New SolidBrush(Color.Blue)
Dim bBrush As New SolidBrush(Color.Yellow)
gridCol.PaintCol(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!