Link to home
Start Free TrialLog in
Avatar of Mehram
MehramFlag for Pakistan

asked on

VB 6 DataGrid Control

Sir, I have one control on my form namely Datagrid. A on column of this grid is amount also have one label for showing user sum of amount which they have put in grid:

Example:

First time user enter in amount 1000 then label will be show 1000
Second time user enter in amount 500 the label will automatically change on update datagrid and show 1500

Please help.

Rgds.
Mehram
Avatar of assyst
assyst

Try the below code,

Get the colindex for the particular amount column

-------------------------------------------------------------------------------------

Private Sub DataGrid1_AfterColUpdate(ByVal ColIndex As Integer)
Dim x%,i%
x = 0
if colindex = <column index of amount field>
    For i = 0 To DataGrid1.ApproxCount - 1
        DataGrid1.Row = i
        x = x + Val(DataGrid1.Columns(ColIndex).Text)
    Next
    Label1.Caption = x
End Sub
You can also do the same with the recordset object.. In the aftercolupdate event of the
datagrid.. just loop the recordset and sumup the amount field and display in the label


Good Luck
Avatar of Mehram

ASKER

Sir I am using following code :

Private Sub DG_AfterColUpdate(ByVal ColIndex As Integer)
Dim x%, i%
x = 0
If ColIndex = Dg.ColIndex(2) Then
    For i = 0 To Dg.ApproxCount - 1
        Dg.Row = i
        x = x + Val(DataGrid1.Columns(2).Text)
    Next
    SkinLabel19.Caption = x
End Sub

neither it is not showing any thing on skinglabel19 nor showing any error
Try after pasting this code
--------------------------------------------------------------

Private Sub DG_AfterColUpdate(ByVal ColIndex As Integer)
Dim x%, i%
x = 0
If ColIndex = 2 Then
    For i = 0 To Dg.ApproxCount - 1
        Dg.Row = i
        x = x + Val(DataGrid1.Columns(2).Text)
    Next
    SkinLabel19.Caption = x
End Sub
Avatar of Mehram

ASKER

Sir no progress
A Slight Change is there in the above code.....

Sorry....

Please paste the below code and run....

-----------------------------------------------

Try after pasting this code
--------------------------------------------------------------

Private Sub DG_AfterColUpdate(ByVal ColIndex As Integer)
Dim x%, i%
x = 0
If ColIndex = 2 Then
    For i = 0 To Dg.ApproxCount - 1
        Dg.Row = i
        x = x + Val(Dg.Columns(2).Text)
    Next
    SkinLabel19.Caption = x
End Sub

----------------------------------------------------------------

Good Luck
Avatar of Mehram

ASKER

Same no progress no error
ASKER CERTIFIED SOLUTION
Avatar of assyst
assyst

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mehram

ASKER

Sir Recrodset is running good I do not no why its not work on datagrid. However my problem resolve. Tks for assistance