Basically, I have a form that when the user hits a "commit" button, it writes a line to a datagrid. In turn, another section of the form displays the payment info. If one vendor is used more than once, I would like to group it.
Alternatively, I could (and probably will if I don't get an answer in this forum) send the dataset to a temp table in SQL and parse it there, but I didn't want to do that.
Thanks for the input, though.
Ron Repp
If gray hair is a sign of wisdom, then I'm a genius.
Don't use the datatable that is actually holding the records to display the records in the grid, but use a separate datatable and dataview to show the grouping.
First, create the datatable for the grouping:
Dim dtGroups As Datatable
dtGroups = New Datatable
'Add columns to the datatable
Dim dcVendorName as DataColumn
Dim dcVendorID as DataColumn
Dim dcAmount as DayaColumn
dcVendorName = New DataColumn
dcVendorName.ColumnName = "VendorName"
dcVendorName.DataType = System.Type.GetType("System.String")
'bind dataview to datagrid
dgGroups.DataSource = dvGroups
Next, when users click the "commit" button, after the data are added to the "real" datatable (the one holding individual records) have the program do something like this:
dvGroups.Sort("VendorID")
Dim i as Integer = -1
'intCurrentVendorID is the VendorID for the current record being entered
i = dvGroups.Find(intCurrentVendorID)
Dim drv As DataRowView
If i >= 0 Then 'vendor is already in the table
'get the appropriate record
drv = dvGroups(i)
'update data in vendor's record
drv.Item("Amount") += ThisRecordAmount
Else 'vendor is not already in the table, so add it
drv = dvGroups.AddNew()
'add data in new vendor's record
drv.Item("VendorName") = ThisVendorName
drv.Item("VendorID") = ThisVendorID
drv.Item("Amount") += ThisRecordAmount
drv.EndEdit()
End If
This should provide you with a grouping of the vendors as records are added. You can tweak this to allow for records being deleted - basically just reverse what was done with dtGroups and dvGroups. If the value of a vendor's Amount drops to 0, remove them from the table.
This is kind of a lot of work for this, but I think it will be better than having to go to the database every time.
Let me know if you need any clarification, etc.
I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.