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.ColumnCount =
dataSet.Tables["customers"].Columns.Count; //THIS IS THE LINE.
VS says :
NullRefrenceException was not handled
Object reference not set to an instance of an object.]
Troubleshooting 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.DataGridView dataGridView2;
and its properties are set like this :
this.dataGridView2.ColumnHeadersHeightSizeMode =
System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView2.Location = new System.Drawing.Point(5, 50);
this.dataGridView2.Name = "dataGridView2";
so why is it null!
thanks
Gideon
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?