Hi all.
My problem is probably ignorance as to how the DGV works, anyway, the problem.

I have a bound datagridview which is used to collect user input. Data for 3 of the 7 fields is entered by looping through the rows and progmatically entering common data anfter a 'Save' Button is pressed:

For I = 0 To DG1.RowCount - 2
DG1.Rows(I).Cells(4).Value = TextBox1.Text 'Operator
DG1.Rows(I).Cells(5).Value = TextBox2.Text 'Date
DG1.Rows(I).Cells(6).Value = TextBox3.Text 'Time 
Next
DG1.Update

Prior to this loop I delete the last unused row if its not a new row:

DG1.CurrentCell = DG1.Item(0, DG1.RowCount - 2)
If DG1.CurrentCell.Value.ToString = "" Then
DG1.Rows.RemoveAt(DG1.RowCount - 2)
DG1.Update()
End If

At this point the DGV looks the way it should...All fields completed correctly and no un used ro except for the new row.

After saving :

Me.ItemTableTableAdapter.Update(Me.StockMoveDataSet.ItemTable)

The 'Operator', 'Date', and 'Time' are not saved to the database for the first row only

Can someone please help me.
Thanks
(Rate)

Recommended Answers

All 2 Replies

I highly recommend you look into data binding, as it will save you a lot of time and virtually all of the code you've listed above.

Data binding will allow you to bind data from the datatable to your datagridview. When this happens all you do is initiate a fill event to populate the entire grid, allow modifications if you want, and use an update command to save. It automates a lot of the process for you...

Good Luck!

Thanks for your reply.
I dont think I have explained myself to correctly if thats how you are interpreting my post.
Please let me explain the best I can. I apreciate your patience with newbies.
I have an input for form with 3 TextBoxes. These TextBoxes collect the common data ie. Operator, Date, and Time.
On the form is also a blank DGV displaying one line without data but bound. The operator enters an ItemCode, ItemDesription, OpeningBalance, and Location without seeing the other 3 fields - Operastor, Date, Time.
When btnSave is pressed, the procedure copies the Operator, Date, and Time to the appropriate fields if rows(I).cells(0) has an ItemCode entered. The procedure then goes on to delete the last row if it is unused and not a new row. All this works fine. Im sure there is an easier way to perform this task but this is the only way I was able to get it to work the way I wanted....trying to make the process 'idiot proof' for the user.
Now....when I save the data supplied to the DGV, the Operator, Date, and Time is not saved for the first line of the DGV only. Please understand I am very new to all this and am finding it all a bit thick on terminology.
I hope this explains it a bit better.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.