这是代码:
private void btnView_Click(object sender, EventArgs e)
{
// MessageBox.Show("lulu");
try
{
String strText=null;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i] == null)
{
}
else if (dataGridView1.Rows[i].Cells[2].Value.ToString() == "-None-")
continue;
else
{
strText = dataGridView1.Rows[i].Cells[0].Value.ToString();
strText += " ";
strText += dataGridView1.Rows[i].Cells[2].Value.ToString();
//this.textBoxView.Text = strText;
}
//i++;
}
//MessageBox.Show(strText);
}
catch(Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
不明白为什么老报Object reference not set to an instance of an object这个错误,修正一下还是这样,请高手指点。谢谢
private void btnView_Click(object sender, EventArgs e)
{
// MessageBox.Show("lulu");
try
{
String strText=null;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i] == null)
{
}
else if (dataGridView1.Rows[i].Cells[2].Value.ToString() == "-None-")
continue;
else
{
strText = dataGridView1.Rows[i].Cells[0].Value.ToString();
strText += " ";
strText += dataGridView1.Rows[i].Cells[2].Value.ToString();
//this.textBoxView.Text = strText;
}
//i++;
}
//MessageBox.Show(strText);
}
catch(Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
不明白为什么老报Object reference not set to an instance of an object这个错误,修正一下还是这样,请高手指点。谢谢
解决方案 »
- c#用打包工具应用程序出来后是源文件还是什么?
- 如何删除datagridview中最下面的几个的空行?
- 我如何通过 字符串来取得相应的参数值啊?(我用的是C# )
- Remoting方法在执行一个操作时,租用期会不会过期
- 如何删除WEB工程中文件,新手啊,请懂的高手们进来帮忙解决一下
- 在安装最新的微软更新后,调用COM出错,“因为配置类型不正确,系统无法开始服务器进程。请检查用户名和密码。”?
- 求viusal studio .net 2003下载,要高速,谢谢
- VC控件的问题
- .Net是做什么的呀/??郁闷
- 关于datagridview排序问题!!!
- 关于ImageList和pictureBox的问题
- .aspx的背景如何设置?
改为
String strText= "";
改成
String strText=new String();
要不就直接写成
string strText = "";
沒實例化對象就報這錯誤,2樓的應該就可以了
JFJF
是因为datagridview的数据改变了,才出现此问题。顺便问一下:datagridview控件的数据改变后(例如在可视化编辑下手动改变了datagridview某一单元的值后),如何获得该单元改变后的值????
此时获得单元格改变后的值时,就会报这个错误