c#将Datagridview Value传递给label [英] c# Pass Datagridview Value to label
本文介绍了c#将Datagridview Value传递给label的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
iam卡在这里plz急需给我一个解决我的下面的错误
iam stuck here plz urgent give me a solution of my below error
private void dgvWpRate_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
label132.Text = dgvWpRate.Rows[0].Cells[0].Value.ToString();
label133.Text = dgvWpRate.Rows[1].Cells[0].Value.ToString();
}
datagridview有1列和6个,我想传递值(仅指使用数字)
到label.text 。
i有六个标签来获得六行值。
当我点击datagridview单元格显示如下错误
未处理的类型'异常' test.exe中发生System.NullReferenceException
附加信息:对象引用未设置为对象的实例。
datagridview have 1column and 6rows,i want to pass the value (means using numbers only)
to label.text.
i have six labels to get the six rows values.
when i click on datagridview cell show below error
An unhandled exception of type 'System.NullReferenceException' occurred in test.exe
Additional information: Object reference not set to an instance of an object.
推荐答案
尝试下面的代码,您可能有单元格值的空值。
try below code, you may have null values for cell values.
label132.Text = dgvWpRate.Rows[0].Cells[0].Value as string;
label133.Text = dgvWpRate.Rows[1].Cells[0].Value as string;
这篇关于c#将Datagridview Value传递给label的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文