473,770 Members | 5,925 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

NullReferenceEx ception on DataGridView.Co lumns Index property

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.

Sep 13 '06 #1
5 4879
Well, lets check the simple cause first. Does the column named "Rating"
exist when this code executes?

Thanks,

Seth Rowe

Kathy wrote:
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.
Sep 14 '06 #2

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.

Sep 14 '06 #3
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.C olumns.Add("Rat ing", "Rating")
Dim values() As String = {"*", "**", "***", "****"}
For i As Integer = 0 To 4
DataGridView1.R ows.Add(values( i))
Next i

Let me know what you find out.

Thanks,

Seth Rowe
Kathy wrote:
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.
Sep 14 '06 #4

rowe_newsgroups wrote:
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.C olumns.Add("Rat ing", "Rating")
Dim values() As String = {"*", "**", "***", "****"}
For i As Integer = 0 To 4
DataGridView1.R ows.Add(values( i))
Next i

Let me know what you find out.

Thanks,

Seth Rowe

I did not add the column in code. If I go into Edit Columns now,
Rating is one of the columns in the list. AND its properties shows
Rating as the DataPropertyNam e as well as the HeaderText.

Thanks,
Kathy

Sep 14 '06 #5
I got it working by changing the following:

If e.ColumnIndex = Me.dataGridView 1.Columns("Rati ng").Index _

to:

Dim col as New DataGridViewCol umn

col = Me.dataGridView 1.Columns(e.Col umnIndex)

if col.DataPropert yName = "Rating" _
I guess Microsoft needs to correct their documentation ;)

Kathy

Sep 14 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1758
by: statlerw | last post by:
I have successfully implemented drag and drop in my application to allow the reordering of columns by dragging and dropping them in the same datagridvire (Net 2.0). If i take it relatively slowly this works perfectly. However, if I perform consecutive drag and drops quickly, the code seems to trip over itself and throws the exception or other similar ones as per below. The main problem is that no matter where I try to catch this...
7
12631
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's the background for my question... Before I switched my application over to the Fx 2.0, I used a DataGrid to display my data. I would store different DataGridTableStyles (each one with a custom set of columns) in the DataGrid.TableStyles property...
2
4886
by: Karen Hill | last post by:
I have a datagridview control on a form with a few of the columns being DataGridViewCheckBox. Whenever I click on the checkbox to create a new record I get a NullReference Exception thrown even though I check for NULL using System.Convert.IsDbNull function. What gives? I'm catching the NullReferenceException, although I know it is not correct to do for normal program flow. What is the solution?
0
2321
by: schoultzy | last post by:
Hello Everyone, I have been trying to figure this one out for two days now. I have created a DataGridView which is populated by an ObjectDataSource. My problem occurs when I attempt to use the Edit feature of the DataGridView. I have set several of the BoundField elements of the DataGridView to ReadOnly="True". When I attempt to use the Edit feature to UPDATE the rows in the DataGridView I get a System.NullReferenceException for...
3
22853
by: connected | last post by:
I'm having difficulty with populating a DataGridView control with data correctly. It works with a single class, for example... class MyClass { private string _propertyOne; private string _propertyTwo; public string PropertyOne { get { return this._propertyOne; } }
3
1837
by: Johnny E. Jensen | last post by:
Hello Dot sure if this it the right group but here goes. I'am using the DataGridView multiple times in my application, and then i'll read a book on inherience, and that opend a new world for me. So i'll Created a class that inherience from the DataGridView Like: public class AWDataGridView : System.Windows.Forms.DataGridView In the Dispose event i'll want to store some info about the DataGridView's
8
11533
by: Brian Pelton | last post by:
This is on .Net 2.0 in a WinForms application. I have a DataGridView that is bound to a BindingSource. The DataGridView has 3 columns. The first two are "normal" text columns and the last is a combo box column. Data binding is working fine for the first two columns. I am able to edit values and persist them back to the bound object and ultimately back to the database.
7
15660
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is there an equivalent property for the DataGridView? I have searched, but have not found one. I would like the user to be able to see all the columns of the table on one screen - thus eliminating the need to use the horizontal scroll bar to view...
6
2854
by: Miro | last post by:
Sorry for the cross post. I am stuck. I have a datagridview for poker rounds. Basically there are 3 columns in this datagridview. "Round" "SmallBlind" "BigBlind" I have an issue when I tab through the new row being added. It does not 'Add' that row, nor setup the 'next blank add row' so I can continue to tab
0
9591
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10002
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.