未将对象引用设置到对象的实例 ,遇到这个错误两次了,下面链接文章中的代码,说给指点下怎么出这个问题
http://www.cnblogs.com/perfect/archive/2008/02/22/1078189.html [Description("设置 DataGridView属性"), Browsable(true), Category("N8")]
public DataGridView DataGridView
{
get
{
return dataGridViewHost.Control as DataGridView; //运行到此句出错
}
}
未处理 System.NullReferenceException
Message="未将对象引用设置到对象的实例。"
Source="WindowsApplication21"
StackTrace:
在 WindowsApplication21.comboboxDataGrid.get_DataGridView() 位置 G:\SampleSoftware\DataWindow\DataWindow\comboboxDataGrid.cs:行号 60
在 WindowsApplication21.Form1..ctor() 位置 G:\SampleSoftware\DataWindow\DataWindow\Form1.cs:行号 36
在 WindowsApplication21.Program.Main() 位置 G:\SampleSoftware\DataWindow\DataWindow\Program.cs:行号 17
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
http://www.cnblogs.com/perfect/archive/2008/02/22/1078189.html [Description("设置 DataGridView属性"), Browsable(true), Category("N8")]
public DataGridView DataGridView
{
get
{
return dataGridViewHost.Control as DataGridView; //运行到此句出错
}
}
未处理 System.NullReferenceException
Message="未将对象引用设置到对象的实例。"
Source="WindowsApplication21"
StackTrace:
在 WindowsApplication21.comboboxDataGrid.get_DataGridView() 位置 G:\SampleSoftware\DataWindow\DataWindow\comboboxDataGrid.cs:行号 60
在 WindowsApplication21.Form1..ctor() 位置 G:\SampleSoftware\DataWindow\DataWindow\Form1.cs:行号 36
在 WindowsApplication21.Program.Main() 位置 G:\SampleSoftware\DataWindow\DataWindow\Program.cs:行号 17
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
要不你把DataGridView初始化下试试