Hello,
I have a datagrid which I am using Linq to fill, I then add some custom columns and fill them in programmaticly - if the users clicks on the column header to re-sort, all the data in the added columns disapears. I am obviously missing something very basic here but can't seem to see the forest for the trees.
I also have a couple of other questions about how I am doing things:
- in my code I am accessing the datagrid custom cells by name, but the cells from the linq I have to use a cell reference number (ie: (1,2) instead of (total,2) (I realize that the name is replaced by a int) - can I name the columns? How about if the end user re-orders them?
This is one of the first times I have used a datagrid like this so any pointers would be nice.
Linq code to pull data
Dim query = From m In db.details _
Where m.InboundDate >= CType(MonthCalendar1.SelectionStart, DateTime) _
And m.InboundDate <= CType(MonthCalendar1.SelectionEnd, DateTime).AddHours(23).AddMinutes(59) _
And m.ClientNo = 1 _
Join md In db.Manifests On md.ManifestID Equals m.MainID _
Select m.Zone, m.MainID, m.InboundDate, m.Zip, md.LadingPkgQty, m.Weight
code to fill with data and add columns
billingDatagrid.DataSource = query
billingDatagrid.Columns.Add("Package Rate", "Package Rate")
billingDatagrid.Columns.Add("LTL", "LTL Rate")
billingDatagrid.Columns.Add("Freight", "Freight")
billingDatagrid.Columns.Add("Fuel Surcharge", "Fuel Surcharge")
billingDatagrid.Columns.Add("Linehaul", "Linehaul")
billingDatagrid.Columns.Add("Billed Amount", "Billed")
Code example of how I am accessing the datagrid columns:
Select Case currentZone
Case 1
packageRate = Val(billingDatagrid(4, currentrow).Value) * zone1PkgRate
billingDatagrid("Package Rate", currentrow).Value = packageRate
If Val(billingDatagrid(5, currentrow).Value) > 500 Then
LTLCharge = zone1_ltlBase + (Val(billingDatagrid(5, currentrow).Value) - 500) * zone1_ltlOver
Else
LTLCharge = zone1_ltlBase
End If
billingDatagrid("LTL", currentrow).Value = LTLCharge
At the end of all this I am going to have to create a .csv file for export - it is obviously important that the correst data stay with each row!
Thanks in advance for advice,
--Joe