VB.NET DataGrid

Hey,

I am trying to display a column at the far right of the datagrid which would have the total of all the values for each individual row.

I added a datacolumn by setting it's expression property, but, this works only if you change rows for a column. For eg. if I have only one row the total will not update.

I wrote code in the textchanged event of each column, the total goes haywire sometimes..works most of the time...(I do trap the current value of each cell...)

Should I use a combination of both or is there a better and easier way to do this

Also, if there a way to pass a value to the expression property of the datacolumn at runtime...

I have been stuck with this for a while and any help will be highly appreciated...thanks a lot..

arjun


Answer this question

VB.NET DataGrid

  • Talons

    Well...
    I figured I could sum it up with a combination of "CurrentCellChanged" on the Grid and "RowChanged" on the dataset....
    Arjun

  • gman108362

    I guess I didn't mention this...
    The user can type in values at runtime and the column needs to be updated simultaneously...

  • Shamus Xu

    So modify the query at runtime, based on user input, reexecute and rebind.  Or get fancy and create a parameter array for your command object that accepts the necessary input.

    Even with execution and bind time, you will still be best off to let the the database engine do a long calculation like that, rather than try to work the values yourself.

  • malhyp

    The best thing to do would be to modify your SELECT statement to include an output field that is the sum of all the other fields you are selecting.

    Even if your datagrid's values aren't coming from a DataSet, whatever you are binding to should allow you to add another field that contains your totals before you populate the grid.

  • Orlanzo

    Thanks rkimble,

    But, the calculation in my GRID is much faster than processing it in the DB. And I don't have to worry about the user losing his current cursor position.
     

  • RomeoChua

    http://www.syncfusion.com/FAQ/WinForms/default.asp#44
  • VB.NET DataGrid