I am trying to set a tooltip for a column cell in a data grid as
documented in the MS Visual Studio 2005 documentation. I set up a test
to match the example exactly including database column, data grid
column and data values. I also have a tooltip control on the form. If
I comment out the 'if' test, it works fine, but uncommented, I get a
NullReferenceEx ception error on the
Me.dataGridView 1.Columns("Rati ng").Index reference. Here is the code
snippet from the help doc:
' Sets the ToolTip text for cells in the Rating column.
Sub dataGridView1_C ellFormatting(B yVal sender As Object, _
ByVal e As DataGridViewCel lFormattingEven tArgs) _
Handles dataGridView1.C ellFormatting
If e.ColumnIndex = Me.dataGridView 1.Columns("Rati ng").Index _
AndAlso Not (e.Value Is Nothing) Then
With Me.dataGridView 1.Rows(e.RowInd ex).Cells(e.Col umnIndex)
If e.Value.Equals( "*") Then
.ToolTipText = "very bad"
ElseIf e.Value.Equals( "**") Then
.ToolTipText = "bad"
ElseIf e.Value.Equals( "***") Then
.ToolTipText = "good"
ElseIf e.Value.Equals( "****") Then
.ToolTipText = "very good"
End If
End With
End If
End Sub 'dataGridView1_ CellFormatting
I'm new to vb.net, so be kind :-)
Thanks for the help.
documented in the MS Visual Studio 2005 documentation. I set up a test
to match the example exactly including database column, data grid
column and data values. I also have a tooltip control on the form. If
I comment out the 'if' test, it works fine, but uncommented, I get a
NullReferenceEx ception error on the
Me.dataGridView 1.Columns("Rati ng").Index reference. Here is the code
snippet from the help doc:
' Sets the ToolTip text for cells in the Rating column.
Sub dataGridView1_C ellFormatting(B yVal sender As Object, _
ByVal e As DataGridViewCel lFormattingEven tArgs) _
Handles dataGridView1.C ellFormatting
If e.ColumnIndex = Me.dataGridView 1.Columns("Rati ng").Index _
AndAlso Not (e.Value Is Nothing) Then
With Me.dataGridView 1.Rows(e.RowInd ex).Cells(e.Col umnIndex)
If e.Value.Equals( "*") Then
.ToolTipText = "very bad"
ElseIf e.Value.Equals( "**") Then
.ToolTipText = "bad"
ElseIf e.Value.Equals( "***") Then
.ToolTipText = "good"
ElseIf e.Value.Equals( "****") Then
.ToolTipText = "very good"
End If
End With
End If
End Sub 'dataGridView1_ CellFormatting
I'm new to vb.net, so be kind :-)
Thanks for the help.
Comment