我的datagrid视图包含从MySQL数据库导入的数据行。我需要做的是将所选行的数据从datagrid视图加载到按钮单击事件上的单独表单。
This is the screenshot of my system
我已经通过将更新书名表单文本框修饰符设置为公开并编写此编码来实现此功能。
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();
}
我知道这不是最好的解决方案,这样做是否有其他选择,以便我可以在更新按钮点击事件中将数据从我的数据网格视图加载到更新书标题窗体?
答案 0 :(得分:0)
使用属性(POCO)类从DataGridView
分配值并将其加载到条目表单中。