• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

adjust the texbox total value

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
Jassimi
Asked:
Jassimi
  • 5
  • 4
1 Solution
 
cdaly33Commented:
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
 
JassimiAuthor Commented:

cdally33,
when I put your code I'm getting this error:
Conversion from String "" to type 'Double' is not valid. Source: Microsoft.VisualVasic
0
 
cdaly33Commented:
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
JassimiAuthor Commented:

what do you mean by (e.RowIndex)
0
 
cdaly33Commented:
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
 
JassimiAuthor Commented:

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
 
cdaly33Commented:
I'm confused then about what your end result needs to be.  Sorry.
0
 
JassimiAuthor Commented:
any body can help ?
0
 
JassimiAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now