关于ref与对象的简单问题?请帮忙 [英] simple question about ref with object?? PLEASE HELP

查看:71
本文介绍了关于ref与对象的简单问题?请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧我在我的应用程序中有一个datagridview,我有一个函数定义如

所以:

public void FillColumns(ref DataGridView theDGV)
$ b当我调用它时$ b ...就像这样:

FillColumns(ref dataGridView2);


i get:对象引用未设置为对象的实例。


i得不到它,是不是我在data.designer.cs中定义的datagridview ????

-private System.Windows.Forms。 DataGridView dataGridView2;


请帮助我......我急需这个!


谢谢

Gideon

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.cs????
-private System.Windows.Forms.DataGridView dataGridView2;

PLEASE HELP ME OUT.. i need this in a hurry!

Thanks
Gideon

推荐答案

它将在InitialiseComponent中初始化,因此您需要确保首先调用

。默认情况下它被设置为在构造函数中调用,所以你在ctor中做了这个,然后你必须把它放在那之后。如果你已经,

那么必须在方法内发生异常


Ciaran O'Donnell
http://wannabedeveloper.spaces.live.com


giddy ;写道:
It will be initialised in InitialiseComponent so you need to ensure that is
called first. It is set to call in the constructor by default so it you do
this in the ctor then you''ll have to put it after that. If you do already,
then the exception must occur inside the method

Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com

"giddy" wrote:

ok我的应用程序中有一个datagridview,我有一个定义为

的函数所以:

public void FillColumns(ref DataGridView theDGV)


当我调用它时...就像这样:

FillColumns(ref dataGridView2);


i get:对象引用未设置为对象的实例。


i得不到它,是不是我在form.designer.cs中定义的datagridview? ????

-private System.Windows.Forms.DataGridView dataGridView2;


请帮助我......我急需这个!


谢谢

Gideon

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.cs????
-private System.Windows.Forms.DataGridView dataGridView2;

PLEASE HELP ME OUT.. i need this in a hurry!

Thanks
Gideon


嗯.. ..是的,我想关于那个,我在按钮期间调用方法

点击事件


private void button1_Click(object sender,EventArgs e)

{

FillColumns(ref dataGridView2);

// CreateDocumentPropertyTable();

}

所以是的, excepti on(NullRefrenceException)发生在函数中。

那么我该怎么做!!!!!!


为什么它说Object引用没有设置为一个物件的实例

OBJECT!

11月22日晚上10点22分,Ciaran O''''Donnell

< CiaranODonn。 .. @ discussion.microsoft.comwrote:
um.. .. yea i thought about that , i call the method during a button
click event

private void button1_Click(object sender, EventArgs e)
{
FillColumns(ref dataGridView2);
//CreateDocumentPropertyTable();
}
so yes, the exception (NullRefrenceException) occurs in the function.
So what do i do!!!!!!

and why does it say Object reference not set to an INSTANCE OF AN
OBJECT!
On Nov 22, 10:22 pm, Ciaran O''''Donnell
<CiaranODonn...@discussions.microsoft.comwrote:

它将在InitialiseComponent中初始化,因此你需要确保首先调用

。默认情况下它被设置为在构造函数中调用,所以你在ctor中做了这个,然后你必须把它放在那之后。如果你已经,

那么必须在方法中发生异常


Ciaran O'Donnellhttp://wannabedeveloper.spaces.live.com


" giddy"写道:
It will be initialised in InitialiseComponent so you need to ensure that is
called first. It is set to call in the constructor by default so it you do
this in the ctor then you''ll have to put it after that. If you do already,
then the exception must occur inside the method

Ciaran O''Donnellhttp://wannabedeveloper.spaces.live.com

"giddy" wrote:

ok我在我的应用程序中有一个datagridview,我有一个定义为

的函数所以:

public void FillColumns(ref DataGridView theDGV)
ok i have a datagridview in my app and i have a function defined like
so:
public void FillColumns(ref DataGridView theDGV)


当我调用它时...就像这样:

FillColumns(ref dataGridView2);
when i call it ... like this :
FillColumns(ref dataGridView2);


i get:对象引用未设置为对象的实例。
i get : Object reference not set to an instance of an object.


i得不到它,是不是我在data.designer.cs中定义的datagridview ????

- private System.Windows.Forms.DataGridView dataGridView2;
i dont get it , is''nt my datagridview defined in form.designer.cs????
-private System.Windows.Forms.DataGridView dataGridView2;


请帮助我......我急需这个!
PLEASE HELP ME OUT.. i need this in a hurry!


谢谢

Gideon
Thanks
Gideon


是与函数在同一范围内的dataGridView2吗?

换句话说,你是从一个没有$ b $的类调用那个函数吗? b知道dgv在哪里?


11月22日下午1:22,giddy < gidisr ... @ gmail.comwrote:
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?

On Nov 22, 1:22 pm, "giddy" <gidisr...@gmail.comwrote:

um .. ..是的,我想到了,我在一个按钮中调用了这个方法

点击事件


private void button1_Click(object sender,EventArgs e)

{

FillColumns(ref dataGridView2);

// CreateDocumentPropertyTable();

}

所以是的,函数中发生异常(NullRefrenceException)。

那么我该怎么做!!!!!!


为什么它说对象引用没有设置为一个实例的对象

OBJECT!


11月22日晚上10点22分,Ciaran O''''Donnell


< CiaranODonn ... @ discussion.microsoft。编写:
um.. .. yea i thought about that , i call the method during a button
click event

private void button1_Click(object sender, EventArgs e)
{
FillColumns(ref dataGridView2);
//CreateDocumentPropertyTable();
}
so yes, the exception (NullRefrenceException) occurs in the function.
So what do i do!!!!!!

and why does it say Object reference not set to an INSTANCE OF AN
OBJECT!

On Nov 22, 10:22 pm, Ciaran O''''Donnell

<CiaranODonn...@discussions.microsoft.comwrote:

它将在InitialiseComponent中初始化,因此您需要确保首先调用

。默认情况下它被设置为在构造函数中调用,所以你在ctor中做了这个,然后你必须把它放在那之后。如果你已经,

那么异常必须在方法
It will be initialised in InitialiseComponent so you need to ensure that is
called first. It is set to call in the constructor by default so it you do
this in the ctor then you''ll have to put it after that. If you do already,
then the exception must occur inside the method


Ciaran O''Donnellhttp:// wannabedeveloper中发生.spaces.live.com
Ciaran O''Donnellhttp://wannabedeveloper.spaces.live.com


" giddy"写道:
"giddy" wrote:

ok我在我的应用程序中有一个datagridview,我有一个定义为

的函数所以:

public void FillColumns(ref DataGridView theDGV)
ok i have a datagridview in my app and i have a function defined like
so:
public void FillColumns(ref DataGridView theDGV)


当我调用它时...就像这样:

FillColumns(ref dataGridView2);
when i call it ... like this :
FillColumns(ref dataGridView2);


i get:对象引用未设置为对象的实例。
i get : Object reference not set to an instance of an object.


i得不到它,是不是我在form.designer.cs中定义的datagridview? ????

-private System.Windows.Forms.DataGridView dataGridView2;
i dont get it , is''nt my datagridview defined in form.designer.cs????
-private System.Windows.Forms.DataGridView dataGridView2;


请帮帮我..我急需这个!
PLEASE HELP ME OUT.. i need this in a hurry!


谢谢

Gideon
Thanks
Gideon


这篇关于关于ref与对象的简单问题?请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆