[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB 6 DataGrid Control

Posted on 2006-07-12
9
Medium Priority
?
374 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Introduction to Processes
Starting up a Project

830 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