M
Mike Cooper
Hello All!
I am getting teh above error message on the following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim dgt As DataGridTableStyle = Main_DataGrid.TableStyles(0)
Dim cm As CurrencyManager = CType(Me.BindingContext _
(Main_DataSet.Tables(dgt.MappingName)), CurrencyManager)
' Get the Rectangle of the clicked cell.
Dim cellRect As Rectangle
Dim cellrow As Integer = 5
Dim cellcolumn As Integer = 1
cellRect = Main_DataGrid.GetCellBounds(5, 1)
' Get the clicked DataGridTextBoxColumn.
Dim gridCol As New MyGridColumn()
gridCol = CType(dgt.GridColumnStyles(cellcolumn),
MyGridColumn)
' Get the Graphics object for the form.
Dim g As Graphics = Main_DataGrid.CreateGraphics()
' Create two new Brush objects: a fore brush and back brush.
Dim fBrush As New SolidBrush(Color.Yellow)
Dim bBrush As New SolidBrush(Color.Yellow)
' Invoke the Paint method to paint the cell with the brushes.
gridCol.PaintCol(g, cellRect, cm, cellrow, bBrush, fBrush,
False)
My MyGridColumn class looks like this:
Public Class MyGridColumn
Inherits DataGridTextBoxColumn
Public Sub PaintCol(ByVal g As Graphics, ByVal cellRect As
Rectangle, _
ByVal cm As CurrencyManager, ByVal rowNum As Integer, ByVal bBrush
As Brush, _
ByVal fBrush As Brush, ByVal isVisible As Boolean)
Me.Paint(g, cellRect, cm, rowNum, bBrush, fBrush, isVisible)
End Sub
End Class
Some of you may recognize this; it is only a slight revision of an
exam given by Microsoft at MSDN. I thought I would be safe using that
code. I get the error at "gridcol = CTYPE" statment. Everything looks
right to me! I have a valid GridTableStyles[0] and a
GridColumnStyles[1].
My only thought: I can't seem to set a variable to a 'type' of
GridColumnStyles. Can anyone tell me if it is correct to reference a
GridColumnstyle directly in this way. ALL SUGGESTIONS WOULD BE
APPRECIATED!!!
I am getting teh above error message on the following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim dgt As DataGridTableStyle = Main_DataGrid.TableStyles(0)
Dim cm As CurrencyManager = CType(Me.BindingContext _
(Main_DataSet.Tables(dgt.MappingName)), CurrencyManager)
' Get the Rectangle of the clicked cell.
Dim cellRect As Rectangle
Dim cellrow As Integer = 5
Dim cellcolumn As Integer = 1
cellRect = Main_DataGrid.GetCellBounds(5, 1)
' Get the clicked DataGridTextBoxColumn.
Dim gridCol As New MyGridColumn()
gridCol = CType(dgt.GridColumnStyles(cellcolumn),
MyGridColumn)
' Get the Graphics object for the form.
Dim g As Graphics = Main_DataGrid.CreateGraphics()
' Create two new Brush objects: a fore brush and back brush.
Dim fBrush As New SolidBrush(Color.Yellow)
Dim bBrush As New SolidBrush(Color.Yellow)
' Invoke the Paint method to paint the cell with the brushes.
gridCol.PaintCol(g, cellRect, cm, cellrow, bBrush, fBrush,
False)
My MyGridColumn class looks like this:
Public Class MyGridColumn
Inherits DataGridTextBoxColumn
Public Sub PaintCol(ByVal g As Graphics, ByVal cellRect As
Rectangle, _
ByVal cm As CurrencyManager, ByVal rowNum As Integer, ByVal bBrush
As Brush, _
ByVal fBrush As Brush, ByVal isVisible As Boolean)
Me.Paint(g, cellRect, cm, rowNum, bBrush, fBrush, isVisible)
End Sub
End Class
Some of you may recognize this; it is only a slight revision of an
exam given by Microsoft at MSDN. I thought I would be safe using that
code. I get the error at "gridcol = CTYPE" statment. Everything looks
right to me! I have a valid GridTableStyles[0] and a
GridColumnStyles[1].
My only thought: I can't seem to set a variable to a 'type' of
GridColumnStyles. Can anyone tell me if it is correct to reference a
GridColumnstyle directly in this way. ALL SUGGESTIONS WOULD BE
APPRECIATED!!!