【发布时间】:2014-05-29 01:28:56
【问题描述】:
我在表单应用程序的组框中有一个 datagridview。我已经制作了这段代码。
private bool checkrow(DataGridViewRow testrow)
{
for (int i = 0; i < testrow.Cells.Count; i++)
{
if (testrow.Cells[i].Value != null)
{
MessageBox.Show(testrow.Cells[i].Value.ToString());
if (testrow.Cells[i].Value.ToString() != string.Empty)
{
MessageBox.Show(testrow.Cells[i].Value.ToString());
return true;
}
}
}
return false;
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
if (checkrow(dgvTimeTracker.CurrentRow) == true)
{
string cbtext = dgvTimeTracker.Rows[dgvTimeTracker.SelectedCells[0].RowIndex].Cells[1].Value.ToString();
MessageBox.Show(cbtext);
string[] newrow = new string[] { DateTime.Now.ToShortDateString(), cbtext, DateTime.Now.ToLongTimeString(), "", "", "" };
}
else
{
MessageBox.Show("Error!");
}
}
如果我在一个新项目上运行此代码,它会完美运行。但是,如果我在我的其他项目中运行它,它只会在获取 datagridview 的组合框项 {1} 列的值时返回“错误”消息或 nullreference 异常
谁能帮帮我吗?
【问题讨论】:
-
如果您发布的代码具有一致的缩进,将会有所帮助。如果您的代码难以阅读,您只会让人们更难帮助您。
标签: c# winforms datagridview combobox nullreferenceexception