|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
NullReferenceException on DataGridView.Columns Index propertydocumented 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 NullReferenceException error on the Me.dataGridView1.Columns("Rating").Index reference. Here is the code snippet from the help doc: ' Sets the ToolTip text for cells in the Rating column. Sub dataGridView1_CellFormatting(ByVal sender As Object, _ ByVal e As DataGridViewCellFormattingEventArgs) _ Handles dataGridView1.CellFormatting If e.ColumnIndex = Me.dataGridView1.Columns("Rating").Index _ AndAlso Not (e.Value Is Nothing) Then With Me.dataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex) 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. Well, lets check the simple cause first. Does the column named "Rating"
exist when this code executes? Thanks, Seth Rowe Kathy wrote: Show quoteHide quote > 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 > NullReferenceException error on the > Me.dataGridView1.Columns("Rating").Index reference. Here is the code > snippet from the help doc: > > ' Sets the ToolTip text for cells in the Rating column. > Sub dataGridView1_CellFormatting(ByVal sender As Object, _ > ByVal e As DataGridViewCellFormattingEventArgs) _ > Handles dataGridView1.CellFormatting > > If e.ColumnIndex = Me.dataGridView1.Columns("Rating").Index _ > AndAlso Not (e.Value Is Nothing) Then > > With Me.dataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex) > > 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. rowe_newsgroups wrote:
> Well, lets check the simple cause first. Does the column named "Rating" Yes it does. It is visible in the column properties within the> exist when this code executes? > > Thanks, > > Seth Rowe > datagridview. Are you adding the Rating Column with code or by using the "Add Column"
dialog in design view? Also what are you putting in for the Name property and the Header Text property of the column? I used the following in my form_load event to add the "Rating" column and everything works fine. DataGridView1.Columns.Add("Rating", "Rating") Dim values() As String = {"*", "**", "***", "****"} For i As Integer = 0 To 4 DataGridView1.Rows.Add(values(i)) Next i Let me know what you find out. Thanks, Seth Rowe Kathy wrote: Show quoteHide quote > rowe_newsgroups wrote: > > Well, lets check the simple cause first. Does the column named "Rating" > > exist when this code executes? > > > > Thanks, > > > > Seth Rowe > > > > Yes it does. It is visible in the column properties within the > datagridview. rowe_newsgroups wrote:
Show quoteHide quote > Are you adding the Rating Column with code or by using the "Add Column" I did not add the column in code. If I go into Edit Columns now,> dialog in design view? Also what are you putting in for the Name > property and the Header Text property of the column? I used the > following in my form_load event to add the "Rating" column and > everything works fine. > > DataGridView1.Columns.Add("Rating", "Rating") > Dim values() As String = {"*", "**", "***", "****"} > For i As Integer = 0 To 4 > DataGridView1.Rows.Add(values(i)) > Next i > > Let me know what you find out. > > Thanks, > > Seth Rowe > > Rating is one of the columns in the list. AND its properties shows Rating as the DataPropertyName as well as the HeaderText. Thanks, Kathy I got it working by changing the following:
If e.ColumnIndex = Me.dataGridView1.Columns("Rating").Index _ to: Dim col as New DataGridViewColumn col = Me.dataGridView1.Columns(e.ColumnIndex) if col.DataPropertyName = "Rating" _ I guess Microsoft needs to correct their documentation ;) Kathy
That Eval Question Again...
Simple Eval() (Ithink) question gradient titlebar in vbdotnet Print the RichTextBox How to return value in Combobox Updating Files IIF referencing both conditional parts regardless of condition? ListBox, ComboBox Bug??? Compiled HTML helpfile does not work when application is installed .NET how to check binary compatability |
|||||||||||||||||||||||