Msflexgrid add totals

Hi.
i have a flexgrid that display me some data from a database,
but I want to add a total row that allows me to get the average of each column, how can i insert a row at the bottom of my flexgrid?
Thank you
ErnestoAsked:
Who is Participating?
 
gecko_au2003Connect With a Mentor Commented:
Here is a good tutorial :

http://pages.cpsc.ucalgary.ca/~saul/vb_examples/tutorial2/

I think it is something like :

flexgrid.AddNew

to add a new row, for attaining a running total of a row you could do something like they showed in the example :

There example :
==================

Private Sub cmdAddEntry_Click()
    'add a new entry to our table.
    With Data1.Recordset
        .AddNew
        !ArtistName = txtArtistName
        !AlbumTitle = txtAlbumTitle
        !Tracks = txtTrackCount
        .Update
    End With
    Data1.Refresh

    'clear the text fields once the new record is added
    txtArtistName = ""
    txtAlbumTitle = ""
    txtTrackCount = ""
 End Sub
================

Modifcation of example :
================

FYI - Insert this code into the click event of the msflexgrid and NOT in a command button. That way it gets the rows values each time you click on a specific row. The coding is something like the below, not sure exactly what it would be because I do not have visual basic installed here and hence I can not test it.

Private Sub cmdAddEntry_Click()
    'add a new entry to our table.
Dim Row1, Row2, Row3,Row4
Dim Total
Dim Average
    With Data1.Recordset
        Row1 = !ArtistName  '<-- assigns each column name to the variable row, make sure you have your column names !
        Row2 =  !AlbumTitle
        Row3 =  !Tracks
        Total = Row1+Row2+Row3
        Average = (Row1+Row2+Row3)/3  '<-- if you can figure out some way of counting the amount
                                                                  'of rows then it will be easier
         .add '<-- just need to figure out how to add each of the variables ( Total and Average)
                       'in to the new row that is created !
        .Update
    End With
    Data1.Refresh
 End Sub

'=======================

I hope the code above gives you a rough idea of what you need to do to do what you are trying to do !

Other then that maybe wait for another expert to answer or reply :)
0
All Courses

From novice to tech pro — start learning today.