ok i have a datagridview in my app and i have a function defined like
so:
public void FillColumns(ref DataGridView theDGV)
when i call it ... like this :
FillColumns(ref dataGridView2);
i get : Object reference not set to an instance of an object.
i dont get it , is'nt my datagridview defined in form.designer.c s????
-private System.Windows. Forms.DataGridV iew dataGridView2;
PLEASE HELP ME OUT.. i need this in a hurry!
Thanks
Gideon
Nov 22 '06
14 1635
Kevin Spencer <sp**@uce.govwr ote:
Now, don't put words in my mouth. I pointed out that it wasn't necessary to
pass the object by reference because I don't know much else about the
problem, but one important aspect to problem-solving is to simplify the
problem. In this case, passing by reference was unnecessary, and, depending
on other factors, *may* have contributed to the problem in some indirect
way. By eliminating that one step, the problem is at least simplified.
But we don't know whether passing by reference was unnecessary or not -
we've only seen the call, not what the method actually did. If the OP
had posted the code to FillColumns, we might well have seen that it was
unnecessary, but as he hasn't, we can't tell.
If you will re-read my post, you will see that the remark about not needing
to pass the DataGridView by reference was the only remark I made.
Indeed, and we don't know whether it was accurate or not - but I
believe it gave an inaccurate impression.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
giddy <gi*******@gmai l.comwrote:
Firstly , i need to use ref because i have a 2 datagrid views that have
to be filled more or less the same way , and i could have a 3rd one
soon. Whatever is common between the dgvs goes into one function and
then obviously has to change the datagridview passed to it.
That in itself doesn't mean you have to pass by reference.
It's very important that you understand reference types and passing by
reference. See http://www.pobox.com/~skeet/csharp/parameters.html
I just tried the whole thing without the ref keyword both in the
function and when i call it. and i GET THE SAME EXCEPTION.
the exception occurs inside the function on the first line :
public void FillColumns(ref DataGridView theDGV)
{
theDGV.ColumnCo unt =
dataSet.Tables["customers"].Columns.Count; //THIS IS THE LINE.
Okay - in that case, either theDGV is null, or dataSet is null, or
dataSet.Tables["customers"] is null, or
dataSet.Tables["customers"].Columns is null.
You should be able to tell that in the debugger.
In Form1.Designer. cs :
the dgv is declared like this : private
System.Windows. Forms.DataGridV iew dataGridView2;
and its properties are set like this :
this.dataGridVi ew2.ColumnHeade rsHeightSizeMod e =
System.Windows. Forms.DataGridV iewColumnHeader sHeightSizeMode .AutoSize;
this.dataGridVi ew2.Location = new System.Drawing. Point(5, 50);
this.dataGridVi ew2.Name = "dataGridView2" ;
so why is it null!
Well, we don't know for sure that it's that that's null - see above for the options.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Hi Jon,
But we don't know whether passing by reference was unnecessary or not -
we've only seen the call, not what the method actually did. If the OP
had posted the code to FillColumns, we might well have seen that it was
unnecessary, but as he hasn't, we can't tell.
I'll have to admit, I made an educated guess. It was highly unlikely (IMHO),
but as I said, I made an educated guess that there was no need in this case.
Indeed, and we don't know whether it was accurate or not - but I
believe it gave an inaccurate impression.
Well, impressions are subjective, but I will certainly grant you that it at
least gave *you* an inaccurate impression, for whatever reason. Furthermore,
if it gave you an inaccurate impression, it might have given others an
inaccurate impression. :)
I have a tendancy to be concise. I often forget that human perception
involves a great deal of interpretation! While I may mean no more and no
less than what I say, I do find that I am sometimes misunderstood, simply
because I didn't clarify my remarks more. If only I had more time!
--
Best Wishes,
Kevin Spencer
Microsoft MVP
Ministry of Software Development http://unclechutney.blogspot.com
Never trust a dunderhead with a blunderbuss.
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************** *@msnews.micros oft.com...
Kevin Spencer <sp**@uce.govwr ote:
>Now, don't put words in my mouth. I pointed out that it wasn't necessary to
<snip>
Indeed, and we don't know whether it was accurate or not - but I
believe it gave an inaccurate impression.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Congratulations ! We've all been there before. I am embarassed on a daily
basis by things that only I know I did!
--
Kevin Spencer
Microsoft MVP
Ministry of Software Development http://unclechutney.blogspot.com
Never trust a dunderhead with a blunderbuss.
"giddy" <gi*******@gmai l.comwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
>
hi ,
i'm really embarrased about this ,
theDGV.ColumnCo unt =
dataSet.Tables["customers"].Columns.Count; //THIS IS THE LINE.
after a 2 more hours of debugging i found out that ......
the DataSet was null not the dgv! =S , and this itself was a cause of
two silly mistakes
I'm really sorry to have wasted your time.
Thank you for your concern!
Gideon
On Nov 23, 9:09 am, "giddy" <gidisr...@gmai l.comwrote:
>ok im sorry if i did'nt give enough detail and i'm really sorry if i'm being rude by saying its urgent , i do have to to finish this project by the end of this month! and a few more setbacks like this could jeopardize a lot more than my job , also i cannnot! afford paid support! i have good programming background but i started C# just a while ago. I made quite a few fuctions with ref, and naturally started to panic when one of them did'nt work!
Firstly , i need to use ref because i have a 2 datagrid views that have to be filled more or less the same way , and i could have a 3rd one soon. Whatever is common between the dgvs goes into one function and then obviously has to change the datagridview passed to it.
I just tried the whole thing without the ref keyword both in the function and when i call it. and i GET THE SAME EXCEPTION.
the exception occurs inside the function on the first line : public void FillColumns(ref DataGridView theDGV) { theDGV.ColumnCo unt = dataSet.Tabl es["customers"].Columns.Count; //THIS IS THE LINE.
VS says :
NullRefrenceEx ception was not handled Object reference not set to an instance of an object.] Troubleshootin g tips : use the 'new' keyword to create an object of the instance (???? check to determine if the object is null before calling the method
i have Form1 , the datagridview is ON Form1 and FillColumns() is in Form1.cs
In Form1.Designer. cs : the dgv is declared like this : private System.Windows .Forms.DataGrid View dataGridView2;
and its properties are set like this : this.dataGridV iew2.ColumnHead ersHeightSizeMo de = System.Windows .Forms.DataGrid ViewColumnHeade rsHeightSizeMod e.AutoSize; this.dataGridV iew2.Location = new System.Drawing. Point(5, 50); this.dataGridV iew2.Name = "dataGridView2" ;
so why is it null!
thanks
Gideon
On Nov 23, 5:18 am, "Kevin Spencer" <s...@uce.gov > wrote:----------------------------------------
Kevin Spencer <s...@uce.govwr ote: A DataGridView is a reference type. There is no need to pass it by ref.
Now, often people *do* use ref when they don't need to, but without
seeing the OP's method, we can't tell whether that's the case or not.
--------------------------------------
>>Peter Duniho wrote:
What line of code does thedebugger say has the null reference? What
variable in that line of
code is the one that is null? And why is it that you expect that variable to NOT be null? --------------------------------------
>>cbmeeks wrote :is the dataGridView2 in the same scope as the function?
In other words, are you calling that function from a class that doesn't know where the dgv is?
Kevin Spencer <sp**@uce.govwr ote:
Congratulations ! We've all been there before. I am embarassed on a daily
basis by things that only I know I did!
That's one of the interesting things about having open source projects
available on the web - *anyone* can see how awful your code is. Having
recently found some clangers in my miscutil library, I'm very red in
the face.
Still, so long as we learn lessons from it... in this case, it's a
retrospective lesson that unit tests make a huge difference :)
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jrlen balane |
last post by:
basically what the code does is transmit data to a hardware and then
receive data that the hardware will transmit.
import serial
import string
import time
from struct import *
ser = serial.Serial()
|
by: Randell D. |
last post by:
HELP!
I am determined to stick with this... I'm getting there... for those who
haven't read my earlier posts, I'm createing what should be a simple
function that I can call to check that required fields in a form have
values. I'm writing the values to the client using document.write only so
that I can confirm that the values are there to be played with - this is not
the final result so please (unless it's leading to the script failure)...
|
by: Rob Somers |
last post by:
Hey all
I am writing a program to keep track of expenses and so on - it is not
a school project, I am learning C as a hobby - At any rate, I am new
to structs and reading and writing to files, two aspects which I want
to incorporate into my program eventually. That aside, my most
pressing problem right now is how to get rid of the newline in the
input when I use fgets(). Now I have looked around on the net, not so
much in this group...
|
by: Peter |
last post by:
Hello
Thanks for reviewing my question. I would like to know how can I programmatically select a node
Thanks in Advanc
Peter
|
by: Tal Sharfi |
last post by:
Hi everyone
I recently had the need for StringGrid object same as the one that
Delphi has. An object that helps show lists of other objects in a
simple grid. I searched the news groups and found none, so, I wrote
one and decided to share it with you.
It's a very simple one with few functions. I derived a DataGrid and
added to it a DataTable to hold the data. The object itself is
handling the synchronization between them, because...
| |
by: jm |
last post by:
Easy probably, please read on. I know some of you have commented
already about some of my socket question. I appreciate that.
I have a Form1:
static void Main()
{
Application.Run(new Form1());
clsListening.AsynchronousSocketListener.StartListening();
|
by: NewInTheGame |
last post by:
I'm a beginner in VB.Net. I'm actually taking a class & so far I
understand everything, but I suck when it comes to arrays. I'm sure
that this is simple (I'm ashamed of asking :oops: )...
I have some textboxes. I'm trying to store the information in an
array, but I'm lost as to how: I have textboxes for FirstName,
LastName & PhoneNumber.
My problem is that the number of arrays is unknown so our teacher
wants us to declare it as...
|
by: Claudio Grondi |
last post by:
In the process of learning about some deeper details of Python I am
curious if it is possible to write a 'prefix' code assigning to a and b
something special, so, that Python gets trapped in an endless loop in a
line with:
if a==b: print 'OK'
I mean, it would be of much help to me on my way to understanding Python
to know how such prefix code leading to an endless loop can look like
and if it is eventually not possible to write such...
|
by: Chris M. Thomasson |
last post by:
I use the following technique in all of my C++ projects; here is the example
code with error checking omitted for brevity:
_________________________________________________________________
/* Simple Thread Object
______________________________________________________________*/
#include <pthread.h>
extern "C" void* thread_entry(void*);
|
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...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |