DataGrid Sum into TextBox

This one seems to be difficult question. I have a VB.Net Form App using an SQLConnection which has a Master/Details setup where the Data for a Transaction number is displayed in a DataGrid. 
I would like to total the fourth column of the display datagrid - not the entire table - and palce it into a text box. 
I am useing two sqladapters (One for a Package Table and one for the Details Table) and a DataSet called DsCrate1. 
On the textchanged for the Transaction number this code fills the dataGrad: DataGrid1.setDataBindings.Fill(DsCrate1, "Package.Transno"). 

I used the TextMatrix Propertiy in VB 6.0 to perform this, but .Net is somewhat new to me. 

I've tried several suggestions to get it to work, but they all seem to apply only to Web Apps.

Can this be done, or have I reached another limitation of VB


Answer this question

DataGrid Sum into TextBox

  • Kobe

    FTY: Any limitation you find in VB is due to your inexperence, not being rude or anything, it's just an honest statement.

    Comming from a VB6 background as you have stated, you have a whole new world and a whole different way of doing things. What ever you thought you knew, forget it.

    Don't let those C# monkeys get you either, I've had my share of contests with some of them and won every time.

    Anyways, to your problem.

    I'm not sure about your question

    You say you want the total of the forth column but not of the whole table. So am I to assume you want just some of the rows in the table of the forth column

    Also does this need to be static or dynamic

    If dynamic, you can use the sum feature in SQL

    select *, sum(doctorfees) as Total from doctortble

    This will give you a column that has the total for all the records returned. Of course if you change values, then this total will not change.

    Now you can always loop though the table and add the stuff up

    Dim Total as double
    Dim DR as datarow
    for each dr in datatable.rows
    if isdbnull(dr.item("doctorFees")) = false then
    total += dr.item("DoctorFees")
    end if
    next

    Textbox1.text = total

    then there is what's called calculated data columns, search for that, I don't have that info readly on hand.

    Hope this helps

  • DataGrid Sum into TextBox