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
Solved

adjust the texbox total value

Posted on 2009-03-31
9
183 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
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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