[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VB 6 DataGrid Control

Posted on 2006-07-12
9
Medium Priority
?
371 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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.
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 …
Progress

656 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