0
votes

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. 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.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.

Thanks in advance.

1
Why cant they edit the text in the DGV? If there are data types like DateTime, the DGV will validate edits but a text box will not. - Ňɏssa Pøngjǣrdenlarp
It is because of DateTime as you mentioned, the "textbox is masked for DateTime, because if someone puts an incorrect dateTime in the datagridview it comes up with an error, and the average user may not understand this. - Octo
A masked edit control will not enforce valid dates. You can control the format for the datecolumn in the DGV much the same way plus it will only allow valid dates. Also you can (should) handle those errors - Ňɏssa Pøngjǣrdenlarp

1 Answers

1
votes

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

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

or easier

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