【发布时间】: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();
}
我知道这不是最好的解决方案,是否有其他选择,以便我可以在更新按钮单击事件时将数据从我的数据网格视图加载到更新书名窗口窗体?
【问题讨论】: