Link to home
Start Free TrialLog in
Avatar of Jassimi
JassimiFlag for Bahrain

asked on

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
Avatar of cdaly33
cdaly33
Flag of United States of America image

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

Avatar of Jassimi

ASKER


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

Avatar of Jassimi

ASKER


what do you mean by (e.RowIndex)
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
Avatar of Jassimi

ASKER


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
I'm confused then about what your end result needs to be.  Sorry.
Avatar of Jassimi

ASKER

any body can help ?
ASKER CERTIFIED SOLUTION
Avatar of Jassimi
Jassimi
Flag of Bahrain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial