0

我有 2 个表单..gridForm有一个dataGridView从数据库获取数据,第二个editForm表单textboxes类似于gridView Columns.

我想选择一行grid然后单击一个编辑按钮,editForm必须显示并且文本框具有来自网格的值

网格表格

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();
        }
    }

编辑表格:

    public string edditContactNameSetter 
    {
        set { txtContactName.Text = value; }
    }

    public string edditJobTitleSetter
    {
        set { txtJobTitle.Text = value; }
    }

    public string edditCompanyNameSetter
    {
        set { txtCompanyName.Text = value; }
    }

展览:

当我从网格中选择任何行时,展览就会出现 在此处输入图像描述

4

1 回答 1

0

好的,我发现了问题,而且由于我是 c# 的新手,我认为这对于专业人士来说是一个天真的错误。

问题出在SELECT FROM查询中,我只是没有companyName从数据库中选择值,所以row.Cells["CompanyNameGridViewColumn"].Value获取null.

于 2013-10-04T19:12:07.203 回答