【问题标题】:How to load data from a datagrid view to a separate windows form on a button click event?如何在按钮单击事件上将数据从数据网格视图加载到单独的窗口窗体?
【发布时间】:2016-09-04 11:04:29
【问题描述】:

我的数据网格视图包含从 MySQL 数据库导入的数据行。我需要做的是将所选行的数据从数据网格视图加载到按钮单击事件的单独表单中。

This is the screenshot of my system

我已经通过将 Update Book Title 表单文本框修饰符设置为 Public 并编写此代码来实现这一点。

private void btn_update_Click(object sender, EventArgs e)
{
    Update_Book_Title form = new Update_Book_Title();

    form.txt_booknumber.Text = this.datagrid_booktitles.CurrentRow.Cells[1].Value.ToString();
    form.txt_isbn.Text = this.datagrid_booktitles.CurrentRow.Cells[2].Value.ToString();
    form.txt_author.Text = this.datagrid_booktitles.CurrentRow.Cells[3].Value.ToString();
    form.txt_booktitle.Text = this.datagrid_booktitles.CurrentRow.Cells[4].Value.ToString();
    form.txt_publishedyear.Text = this.datagrid_booktitles.CurrentRow.Cells[5].Value.ToString();
    form.txt_publisher.Text = this.datagrid_booktitles.CurrentRow.Cells[6].Value.ToString();
    form.txt_category.Text = this.datagrid_booktitles.CurrentRow.Cells[7].Value.ToString();
    form.arrived_date.Text = this.datagrid_booktitles.CurrentRow.Cells[8].Value.ToString();
    form.txt_price.Text = this.datagrid_booktitles.CurrentRow.Cells[9].Value.ToString();
    form.txt_quantity.Text = this.datagrid_booktitles.CurrentRow.Cells[10].Value.ToString();

    form.StartPosition = FormStartPosition.CenterScreen;
    form.MdiParent = this.MdiParent;
    form.Show();
}

我知道这不是最好的解决方案,是否有其他选择,以便我可以在更新按钮单击事件时将数据从我的数据网格视图加载到更新书名窗口窗体?

【问题讨论】:

    标签: c# mysql


    【解决方案1】:

    使用属性 (POCO) 类分配来自DataGridView 的值并将它们加载到输入表单中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-18
      • 1970-01-01
      • 2016-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多