473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DataGridView

102 64KB
Background- Front end Visual Studio 2013 using visual basic, back end MS SQL Server 2012 and I am new to visual basic.

I am using a data grid view. The code is below. The line of code
Expand|Select|Wrap|Line Numbers
  1. DGV_CurrentRatings.Columns.Item("ID_Evaluations").Width = 0
generates the following error message: "Object reference not set to an instance of an object." What am I doing wrong?

Expand|Select|Wrap|Line Numbers
  1.  Dim strSQL As String
  2.  
  3.         strSQL = "Select * FROM Evaluations WHERE FY='" & my_CurrentFY & "' AND MD_Delete='0' AND ID_Supplier=" & my_IDSupplier & " Order By FY DESC, QTR"
  4.  
  5.  
  6.         Try
  7.             Dim connectionString As String = SQL_ConnectionStr2
  8.  
  9.             Dim connection As New SqlConnection(connectionString)
  10.             Dim dataadapter As New SqlDataAdapter(strSQL, connection)
  11.             Dim ds As New DataSet()
  12.             connection.Open()
  13.             dataadapter.Fill(ds, "Authors_table")
  14.             connection.Close()
  15.             DGV_CurrentRatings.DataSource = ds
  16.             DGV_CurrentRatings.DataMember = "Authors_table"
  17.             DGV_CurrentRatings.Columns.Item("ID_Evaluations").Width = 0
  18.             DGV_CurrentRatings.Columns.Item("ID_Supplier").Width = 0
  19.             DGV_CurrentRatings.Columns.Item("FYStatus").Width = 0
  20.             DGV_CurrentRatings.Columns.Item("StatusDateTime").Width = 0
  21.             DGV_CurrentRatings.Columns.Item("EvalStatus").Width = 0
  22.             DGV_CurrentRatings.Columns.Item("EvalStatusDate").Width = 0
  23.             DGV_CurrentRatings.Columns.Item("FY").Width = 40
  24.  
  25.             With DGV_CurrentRatings.ColumnHeadersDefaultCellStyle
  26.                 .Font = New Font(DGV_CurrentRatings.Font, FontStyle.Bold)
  27.             End With
  28.  
  29.         Catch EX As Exception
  30.             MsgBox(EX.Message)
  31.             Return False
  32.             Exit Function
  33.         End Try
Dec 8 '15 #1
3 1278
Luk3r
300 256MB
The real meaning is that you're trying to change the property of an object that does not exist or is null. This just means that the columns were either never created or the name of the column is not a match.
Dec 8 '15 #2
sc5502
102 64KB
The query does return rows and the column is spelled correctly, if this is what you mean.
Dec 8 '15 #3
Luk3r
300 256MB
That is, in fact, what I meant. The fact remains that your code thinks your column doesn't exist. The way you're trying to modify the column width is by means of checking the column header text. You could always try to use an integer in place of the header text for troubleshooting.
Expand|Select|Wrap|Line Numbers
  1. DataGridView1.Columns.Item(0).Width = 0
Dec 10 '15 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: DraguVaso | last post by:
Hi, I'm using the DataGridView in VB.NET 2.0. The DataSource is a Generic List of a custom class0: lstMyPersonnes = New List(Of clsPersonne). When I add a new clsPersonne to lstMyPersonnes,...
10
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. Basically, on my form I have a DataGridView, it's got...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
2
by: bob | last post by:
Can anyone tell me the best way to update a dataset while it is being edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should...
7
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...
7
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...
0
by: jeastman - Hotmail | last post by:
Hello world Excuse, not to be written English and it helps me with a translator. I am new programming in C#. I made a control inheriting the DataGridView to be able to add controls done by...
3
by: Andrus | last post by:
I have DataGridView in virtual mode containing 3500 rows. In code below, assigning to RowCount value to 3500 takes 8 seconds. CPU usage goes high at this time. Stepping by F11 into user code shows...
0
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
2
BRawn
by: BRawn | last post by:
Hi guys, I'm struggling to copy rows from one DataGridView to another. This may sound redundant but it's necessary for my Orders project. I have 3 DataGridViews on one form. The first...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.