我有2个表单.. gridForm
有一个dataGridView
从数据库获取数据,第二个表单editForm
有textboxes
类似于gridView Columns
。
我想在grid
中选择一行,然后点击修改按钮,必须显示editForm
,文本框中包含网格值
gridForm
private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
// when i put this line only , it works right.
edditContactForm.edditContactNameSetter = row.Cells["contactNameGridViewColumn"].Value.ToString();
// this also with the previous is working right too.
edditContactForm.edditJobTitleSetter = row.Cells["jobTitleGridViewColumn"].Value.ToString();
// the problem appears here and the exhibition shown to this line and any similar lines under it.
edditContactForm.edditCompanyNameSetter = row.Cells["CompanyNameGridViewColumn"].Value.ToString();
}
}
editForm:
public string edditContactNameSetter
{
set { txtContactName.Text = value; }
}
public string edditJobTitleSetter
{
set { txtJobTitle.Text = value; }
}
public string edditCompanyNameSetter
{
set { txtCompanyName.Text = value; }
}
展
当我从网格中选择任何一行时,展览会出现
答案 0 :(得分:0)
好的,我发现了问题,因为我是c#的新手,我觉得这对专业人士来说是一个天真的错误。
问题出在SELECT FROM
查询中,我只是没有从数据库中选择companyName
值,因此row.Cells["CompanyNameGridViewColumn"].Value
得到null
。