0

I am working with- window application, VB, VS 2012, .net F/W- 4.5
I have a DGV (datagridview) in form. There are different types of column (dgv-combobox, dgv-textbox) in DGV which are created runtime.

Code: textchanged event (runtime created using addhandler) of DataGridViewTextBoxCell

 Private Sub txt_box_textchanged(sender As Object, e As EventArgs)
        Dim a, b, total_price As Int32
        a = dgv.Rows(0).Cells(3).Value
        b = dgv.Rows(0).Cells(4).Value
        total_price = a * b
        dgv.Rows(0).Cells(5).Value = total_price
 End Sub

Screenshot of DGV inputs:
If I change input value (any of textbox- a or b), it does not affect on output.
In other words, output is not as it should be, like 5*3=15, 4*9=36
But if I change cell and change value of that cell, then output will be of previous input (when last time cell got changed).
Otherwise output remains same until input is coming from same cell.
what I mean by "change cell " is click on any other cell of DGV except current cell.
Please note that all row in image are individual input (only one row- not multiple row of DGV).

I also tried "key up" event of textbox using same code, but same issue. Please guys help me to overcome this issue.

Umesh
  • 71
  • 3
  • 14
  • 1
    The code you have shown always does it's calculations on the first row. If you use `dgv.Rows(0)` then it will always work with the first row. If you want to work with the row the `TextBox` is in then you need to use the index of that row. If you're editing that row then obviously it will be the `CurrentRow`. – jmcilhinney Oct 07 '18 at 11:58
  • 1
    The thing is though, you are using the `Value` of the cells and the `Value` of the cell being edited doesn't change when the `Text` of the `TextBox` changes; only when the editing sessions ends. That's why there's a `CellValueChanged` event. You need to either use a different event or a different property if you expect to use current data. – jmcilhinney Oct 07 '18 at 11:59
  • about first reply- I know that things, but I also wondering that how can I made that mistake, sorry for that, about second reply- your "CellValueChanged" made my day, thanks for it. I have already voted up, but is there any way to accept it as an answer? – Umesh Oct 08 '18 at 06:23
  • What I provided is not really an answer, which is why I didn't post it as one. It was really just a direction for you to investigate. If you've developed an actual solution based on that, you should post it as an answer yourself and accept it. – jmcilhinney Oct 08 '18 at 07:09

0 Answers0