Ok... perhaps people only thought datagrids would be for displaying data, cause it doesn't look like much thought was put into using them for data entry. Private
I have a SQL database. I used to have an Access Front end (.adp) that my users could use to enter data using forms I created. The Network manager cannot explain why this is no longer in existance, but needless to say, I needed to get something for my users
to enter data.
So, I figured a Win Form app, with datagrids so it would have a similar look and field. My form uses a dataset with the required tables and DataRelations.
The updates work mostly, but the form is very clunky. And at times it doesn't work well. Here's a link to a screen shot Listbox (1) is where the user selects the photographer to work with.
This updates the data in datagrids 2 & 3. As they navigate datagrid 2 datagrid 4 updates. I handle the CurrentCellChanged on each of the datagrids and call this function:
Dim tempPosition
As Integer
Dim tempID As
Integer
Dim dsChanges
As DataSet
Dim cmPhotog As CurrencyManager =
DirectCast(Me.BindingContext(Me.dsPhotographers, "Photographers"), CurrencyManager)
Dim cmCodes As CurrencyManager =
DirectCast(Me.BindingContext(Me.dsPhotographers, "Photographers.PhtgToProducts.ProdToCodes"),
CurrencyManager)
Dim cmOffsets
As CurrencyManager =
DirectCast(Me.BindingContext(Me.dsPhotographers, "Photographers.PhtgToOffsets"), CurrencyManager)
Try
If Me.dsPhotographers.HasChanges
Then
cmPhotog.EndCurrentEdit()
cmCodes.EndCurrentEdit()
cmOffsets.EndCurrentEdit()
dsChanges = Me.dsPhotographers.GetChanges
'Products
tempPosition = Me.BindingContext(Me.dsPhotographers, "Photographers.PhtgToProducts").Position
tempID = Me.dsrvc.ProductsUpdate(dsChanges)
Me.dsPhotographers.Tables("Products").AcceptChanges()
If tempID > 0
Then
Me.dsPhotographers.Tables("Products").Rows(Me.dsPhotographers.Tables("Products").Rows.Count - 1)("ProductID") = tempID
End If
tempID = Me.dsrvc.ProductCodesUpdate(dsChanges)
Me.dsPhotographers.Tables("Codes").AcceptChanges() If tempID > 0 Then
Me.dsPhotographers.Tables("Codes").Rows(Me.dsPhotographers.Tables("Codes").Rows.Count - 1)("ProductPriceID") = tempID
End If 'Offsets
tempID = Me.dsrvc.OffsetsUpdate(dsChanges)
Me.dsPhotographers.Tables("Offsets").AcceptChanges() If tempID > 0 Then
Me.dsPhotographers.Tables("Offsets").Rows(Me.dsPhotographers.Tables("Offsets").Rows.Count - 1)("OffsetPriceID") = tempID
End If Me.dsPhotographers.AcceptChanges()
cmPhotog.Refresh()
cmCodes.Refresh()
cmOffsets.Refresh()
Me.BindingContext(Me.dsPhotographers, "Photographers.PhtgToProducts").Position = tempPosition End If Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub It goes and takes the 3 tables (so far that's all we're updating/modifying) and passes them to the update functions. These functions pass back any database generated IDENTITIES. However, to update and refresh these in the datagrids, I do a Refresh, which resets the selected row in the datagrids. This can be very frustrating for the users who might add an item in Datagrid 2, and then want to add items for that in datagrid 4.
Documentation I've seen online has not been very clear on this subject. In fact I was told that anybody who wants to do this type of project gets a different datagrid first. I think that's sad that MS built this tool, but it's only half finished/functional. What can I do? Am I approaching this wrong? My users are screaming for blood, and I don't want to go back to Access Forms!
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.