Solved

VB 6 DataGrid Control

Posted on 2006-07-12
9
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
A short article about problems I had with the new location API and permissions in Marshmallow
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Introduction to Processes

718 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