Solved

VB 6 DataGrid Control

Posted on 2006-07-12
9
349 Views
Last Modified: 2010-04-17
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
0
Comment
Question by:Mehram
  • 5
  • 4
9 Comments
 
LVL 7

Expert Comment

by:assyst
ID: 17088632
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
0
 
LVL 7

Expert Comment

by:assyst
ID: 17088638
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
0
 

Author Comment

by:Mehram
ID: 17088758
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
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 7

Expert Comment

by:assyst
ID: 17088846
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
0
 

Author Comment

by:Mehram
ID: 17088874
Sir no progress
0
 
LVL 7

Expert Comment

by:assyst
ID: 17088875
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
0
 

Author Comment

by:Mehram
ID: 17088963
Same no progress no error
0
 
LVL 7

Accepted Solution

by:
assyst earned 500 total points
ID: 17089005
There is no probelm with the above code. what you can do is just debug the code.
Add a break point by pressing the F9 key and press F8 to proceed. look for the data
values in the datagrid and the values of the variable. You can do it..

Or else.. try it with the recordset option

Replace <recordset> with the corresponding recordset variable name used.

------------------------------------------------------------------------
Private Sub DG_AfterColUpdate(ByVal ColIndex As Integer)
Dim x%
x = 0
   <recordset>.movefirst
    while <recordset>.eof = False
           x = x + Val(<recordset>.fields("Account"))
        <recordset>.movenext
    wend
    SkinLabel19.Caption = x
End Sub
---------------------------------------------------------------------------

Good Luck
0
 

Author Comment

by:Mehram
ID: 17089044
Sir Recrodset is running good I do not no why its not work on datagrid. However my problem resolve. Tks for assistance
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an explanation of a simple data model to help parse a JSON feed
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question