Solved

VB 6 DataGrid Control

Posted on 2006-07-12
9
315 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
thread-safe code in c++ 2 71
Order table with macro 3 75
topping2 challenge 13 58
PHP question(s) about order of output 9 41
This is an explanation of a simple data model to help parse a JSON feed
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now