Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

adjust the texbox total value

Posted on 2009-03-31
9
Medium Priority
?
206 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
[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 9

Expert Comment

by:cdaly33
ID: 24028748
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
ID: 24029224

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
ID: 24029270
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Author Comment

by:Jassimi
ID: 24029554

what do you mean by (e.RowIndex)
0
 
LVL 9

Expert Comment

by:cdaly33
ID: 24029600
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
ID: 24030288

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
ID: 24032248
I'm confused then about what your end result needs to be.  Sorry.
0
 
LVL 2

Author Comment

by:Jassimi
ID: 24036322
any body can help ?
0
 
LVL 2

Accepted Solution

by:
Jassimi earned 0 total points
ID: 24038352
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 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