Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with custom DataGrid control 1

Status
Not open for further replies.

meinhunna

Programmer
Jul 31, 2004
118
0
0
AU
I have created a custom DataGrid control which implements a custom property HighlightRow of type Boolean.

I have another custom DataGridTextBoxColumn class, which Overrides the Paint method in order to facilitate row highlighting.

My question is how I can access the HighlightRow property of custom DataGrid control in DataGridTextBoxColumn class. I want to check this property in Overridden Paint method.

Thanks.
 
((MyCustomDataGrid) Me.DataGridTableStyle.DataGrid).HighlightRow

Note this will only work if your custom DataGridTextBoxColumn class is added to your custom DataGrid class as the type coersion will fail. You might want to put a conditional in there to check the type of the DataGrid and treat it as a false HighlightRow if it is not your custom DataGrid class.
 
((MyCustomDataGrid) Me.DataGridTableStyle.DataGrid).HighlightRow

gives me syntax error. how would i check the type of the DataGrid?
 
I think the syntax is:

Code:
Dim blnHighlightRow As Boolean

If GetType(MyCustomDataGrid) = Me.DataGridTableStyle.DataGrid.GetType() Then
   blnHighlightRow = ((MyCustomDataGrid) Me.DataGridTableStyle.DataGrid).HighlightRow
Else
   'Since this DataGrid does not implement the HighlightRow
   'property, assume that the property is false
   blnHighlightRow = False
End If

Note that you will need to replace "MyCustomDataGrid" with the class name that you have chosen for your custom datagrid.

That might have been the source of your syntax error or it might have been from accessing the HighlightRow property without assigning it to anything.
 
It doesn't like the part ((MyCustomDataGrid) Me.DataGridTableStyle.DataGrid).HighlightRow

I believe this is incorrect VB.NET syntax. Are you trying to convert DataGridTableStyle.DataGrid to MyCustomDataGrid?
 
I apologize, I forgot there is a special VB.NET function for type coersion isn't there?

This is probably what I meant to type:

Code:
Dim blnHighlightRow As Boolean

If GetType(MyCustomDataGrid) = Me.DataGridTableStyle.DataGrid.GetType() Then
   blnHighlightRow = [b]CType(Me.DataGridTableStyle.DataGrid, MyCustomDataGrid).HighlightRow[/b]
Else
   'Since this DataGrid does not implement the HighlightRow
   'property, assume that the property is false
   blnHighlightRow = False
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top