Note that there are some explanatory texts on larger screens.

plurals
  1. POconfusion over datagrid erasing entries and general datagrid access
    primarykey
    data
    text
    <p>I have a datagrid which I am using LINQ to fill, I then add some custom columns and fill them in programmatically - if the users clicks on the column header to re-sort, all the data in the added columns disappears. I am obviously missing something very basic here but can't seem to see the forest for the trees.</p> <p>I also have a couple of other questions about how I am doing things:</p> <ol> <li>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 (i.e.: (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?</li> </ol> <p>This is one of the first times I have used a datagrid like this so any pointers would be nice.</p> <p>LINQ code to pull data </p> <pre><code> Dim query = From m In db.details _ Where m.InboundDate &gt;= CType(MonthCalendar1.SelectionStart, DateTime) _ And m.InboundDate &lt;= 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></pre> <p>code to fill with data and add columns</p> <pre><code>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></pre> <p>Code example of how I am accessing the datagrid columns:</p> <pre><code>Select Case currentZone Case 1 packageRate = Val(billingDatagrid(4, currentrow).Value) * zone1PkgRate billingDatagrid("Package Rate", currentrow).Value = packageRate If Val(billingDatagrid(5, currentrow).Value) &gt; 500 Then LTLCharge = zone1_ltlBase + (Val(billingDatagrid(5, currentrow).Value) - 500) * zone1_ltlOver Else LTLCharge = zone1_ltlBase End If billingDatagrid("LTL", currentrow).Value = LTLCharge </code></pre> <p>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!</p> <p>Thanks in advance for advice.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload