简体   繁体   English

VB.NET:按文本框编辑DataGridView行

[英]VB.NET: Edit DataGridView Row by Textbox

I am new to stack overflow so sorry if I mess something up. 我是堆栈溢出的新手,所以如果我搞砸了,抱歉。

Basically what I have so far is DataGridView called DataDataGridView on Form1. 到目前为止,基本上我拥有的是Form1上称为DataDataGridView的DataGridView。 When one of the rows are clicked it passes the data in the row from each column onto some textboxes on Form2, each textbox holding the data for a seperate column. 单击某行时,它将行中的数据从每一列传递到Form2上的某些文本框,每个文本框保存单独列的数据。 Form2.TextBox1.Text = DataDataGridView.Rows(e.RowIndex).Cells(0).Value.ToString() Form2.TextBox2.Text = DataDataGridView.Rows(e.RowIndex).Cells(1).Value.ToString() Form2.TextBox3.Text = DataDataGridView.Rows(e.RowIndex).Cells(2).Value.ToString() Form2.TextBox4.Text = DataDataGridView.Rows(e.RowIndex).Cells(3).Value.ToString() Form2.TextBox5.Text = DataDataGridView.Rows(e.RowIndex).Cells(4).Value.ToString() Form2.TextBox6.Text = DataDataGridView.Rows(e.RowIndex).Cells(5).Value.ToString() Form2.TextBox7.Text = DataDataGridView.Rows(e.RowIndex).Cells(6).Value.ToString()

What I want is for the user to be able to edit the textbox fields in Form2 and click a submit button to update the DataGridView from the textboxes on Form2. 我想要的是用户能够在Form2中编辑文本框字段,然后单击提交按钮以从Form2上的文本框中更新DataGridView。

Thanks in advance. 提前致谢。

In the buttons click handler just reverse what you've already done. 在按钮中,单击处理程序只需反转已完成的操作即可。 You wont have an e.RowIndex value but assuming this is the current row of the datagridview you can just do 您将没有e.RowIndex值,但假设这是datagridview的当前行,则可以执行此操作

Dim rowIndex = DataDataGridView.CurrentRow.Index 
DataDataGridView.Rows(rowIndex).Cells(0).Value = Form2.TextBox1.Text 
....

or easier 或更容易

DataDataGridView.CurrentRow.Cells(0).Value = Form2.TextBox1.Text 
....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM