1

我有一个DataGridView可以将测试数据添加到我的数据网格视图但是当我想手动输入任何内容(通过文本框和下拉框)时,我只是在我的数据网格视图中添加了一个空白行

这是我的代码:这是进入手动输入数据的表单

private void button1_Click(object sender, EventArgs e)
{
    frmAddReptile frmAddReptile = new frmAddReptile();

    frmAddReptile.ShowDialog();
    _ReptileList.Add(_Reptile);
}

然后,在那个表格上,我有

internal Reptile _Reptile;
private void button1_Click(object sender, EventArgs e)
{
    _Reptile = new Reptile();
    _Reptile.Name = txtName.Text;
    _Reptile.Country = Convert.ToString(cbxCountry.SelectedItem);
    _Reptile.Province = Convert.ToString(cbxProvince.SelectedItem);
    _Reptile.Town = Convert.ToString(cbxTown.SelectedItem);
    _Reptile.Collector = txtCole.Text;
    _Reptile.Length = Convert.ToInt32(txtLen.Text);
    _Reptile.Coordinates =txtCo.Text;
    _Reptile.Weight = Convert.ToInt32(txtwe.Text);
    _Reptile.Date = Convert.ToString(dtpDate.Value.ToShortDateString());

    this.Close();    
}

然后,单击按钮后,只有一个黑色行添加到我的数据网格视图中。

好的,我现在知道是否将所有内容添加到它工作的同一个窗口中(添加到数据网格视图)

private void button1_Click(object sender, EventArgs e)
    {
        _Reptile = new Reptile();
        _Reptile.Name = txtName.Text;
        _Reptile.Country = Convert.ToString(cbxCountry.SelectedItem);
        _Reptile.Province = Convert.ToString(cbxProvince.SelectedItem);
        _Reptile.Town = Convert.ToString(cbxTown.SelectedItem);
        _Reptile.Collector = txtCole.Text;
        _Reptile.Length = Convert.ToInt32(txtLen.Text);
        _Reptile.Coordinates =txtCo.Text;
        _Reptile.Weight = Convert.ToInt32(txtwe.Text);
        _Reptile.Date = Convert.ToString(dtpDate.Value.ToShortDateString());
        _ReptileList.Add(_Reptile);

    }

这就是我现在所拥有的,但我怎样才能让它以不同的形式添加数据,这与它有什么关系internal Reptile _Reptile;吗?

4

0 回答 0