Solved

adjust the texbox total value

Posted on 2009-03-31
9
165 Views
Last Modified: 2013-11-05
hi..
I have an editable datagrid that contains on 3 columns (unit_price, qty, price),
and I have one textbox (txtTOTAL) to count all rows of the price column,

what I want is when the user edit the value of any price cell in the datagrid, the (txtTOTAL) will adjust depends on the changes.

thanks
0
Comment
Question by:Jassimi
  • 5
  • 4
9 Comments
 
LVL 9

Expert Comment

by:cdaly33
Comment Utility
You should able to capture it like this:


  Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged

    Dim row As DataGridViewRow = DataGridView1.Rows(e.RowIndex)

    Dim cell As DataGridViewCell = row.Cells(e.ColumnIndex)
 

    Dim mynewvalue = cell.Value
 

    txtbox.text = txtbox.text + mynewvalue

  End Sub

Open in new window

0
 
LVL 2

Author Comment

by:Jassimi
Comment Utility

cdally33,
when I put your code I'm getting this error:
Conversion from String "" to type 'Double' is not valid. Source: Microsoft.VisualVasic
0
 
LVL 9

Expert Comment

by:cdaly33
Comment Utility
sounds like your cell value doesn't have a value at that point.  to get around that you can do something like this:
  Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged

    Dim row As DataGridViewRow = DataGridView1.Rows(e.RowIndex)

    Dim cell As DataGridViewCell = row.Cells(e.ColumnIndex)

 

    Dim mynewvalue = cell.Value

 

if isnumeric(mynewvalue) then

    txtbox.text = txtbox.text + mynewvalue

end if
 

  End Sub

Open in new window

0
 
LVL 2

Author Comment

by:Jassimi
Comment Utility

what do you mean by (e.RowIndex)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 9

Expert Comment

by:cdaly33
Comment Utility
e.RowIndex is the 0-based index number of row being edited

here you'd be using it to retrieve the row containing the edited cell
0
 
LVL 2

Author Comment

by:Jassimi
Comment Utility

I still facing same error,
the other thing is that I don't want number of row to be fixed..
because sometime when I make search in the datagrid, the rows required will appear and after that I will edit the values
0
 
LVL 9

Expert Comment

by:cdaly33
Comment Utility
I'm confused then about what your end result needs to be.  Sorry.
0
 
LVL 2

Author Comment

by:Jassimi
Comment Utility
any body can help ?
0
 
LVL 2

Accepted Solution

by:
Jassimi earned 0 total points
Comment Utility
ok..
I got the solution
we have to write the following code in CellEndEdit event:
Dim Sum_ As Integer = 0
        With DataGridView1
            For i As Integer = 0 To .Rows.Count - 1
                Sum_ += .Rows(i).Cells("NumInGridView").Value
            Next
            txtSum.Text = Sum_
        End With


it will work fine after any changs in datagrid values

thanks
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

9 Experts available now in Live!

Get 1:1 Help Now