CDCDCD
2019-05-19T11:14:11Z
Hi to all,
What is the best way to capture a valuechanged event on a NumericUpDownCellEditor ?
I've implemented the NumericUpDownCellEditor from page 94 of the following pdf:

https://10tec.com/FS/Products_doc/10Tec_iGrid.NET_6.0_Manual.pdf 

Thanks!
CD
Igor/10Tec
2019-05-20T14:18:30Z
You should attach an event handler to the fNumericUpDown control in the constructor of the NumericUpDownCellEditor class and raise your own event from the fNumericUpDown ValueChanged event.
CDCDCD
2019-05-20T15:02:19Z
Of course! I just had to adapt the handling of the fNumericUpDown ValueChanged event a little because when it got called, my iGrid still had the old un-committed value in, and if I called iGrid.CommitEditCurrentCell, then it would pop out of the numeric up down editing.
The solution seems to be:

In my igNumericUpDownCellEditor class:

    Public Event ValueChanged(sender As Object, e As EventArgs)
    Public Sub New()
        Me.fNumericUpDown = New NumericUpDown() With {
            ...
        }
        AddHandler Me.fNumericUpDown.ValueChanged, AddressOf fNumericUpDown_ValueChanged
        ...
    End Sub
    Private Sub fNumericUpDown_ValueChanged(sender As Object, e As EventArgs)
      RaiseEvent ValueChanged(Me, e)
    End Sub
    Public ReadOnly Property Value() As Decimal
      Get
        Return Me.fNumericUpDown.Value
      End Get
    End Property

And then, in the main program:

With MyGrid.Rows.Add
   ...
   Dim custEdit As igNumericUpDownCellEditor = New igNumericUpDownCellEditor
   .Cells(iCol).Style.CustomEditor = custEdit
   .Cells(iCol).Style.TextAlign = iGContentAlignment.MiddleCenter
   AddHandler custEdit.ValueChanged, AddressOf NumericUpDownCustomCellEditor_ValueChanged
   ...
End With
  Private Sub MyGridNumericUpDownCustomCellEditor_ValueChanged(sender As Object, e As EventArgs)
    For i As Integer = 0 To MyGrid.Rows.Count - 1
      For j As Integer = 0 To MyGrid.Cols.Count - 1
        If sender Is MyGrid.Rows(i).Cells(j).Style.CustomEditor Then
          If CDec(MyGrid.Rows(i).Cells(j).Value) <> CDec(CType(sender, igNumericUpDownCellEditor).Value) Then
            MyGrid.Rows(i).Cells(j).Value = CType(sender, igNumericUpDownCellEditor).Value
            DoOtherStuff
          End If
          Exit Sub
        End If
      Next
    Next
  End Sub

Thanks for putting me on the right track Igor. This iGrid is such a great tool!
Igor/10Tec
2019-05-21T10:23:28Z
Stop - not so fast :)

First, it was not clear from your original post that you need to update the cell value immediately when the value in the NumericUpDown control is changed. Generally, when you edit a cell in iGrid, an editor is placed over the current cell and the new value is saved only when you press ENTER or click outside of the edited cell. This allows you to cancel editing and provides you with the corresponding set of events related to editing (BeforeCommitEdit, AfterCommitEdit, CancelEdit). What you are doing is somewhat different to what we do in iGrid, but if it is exactly what you need - do this.

Second, I do not like the code in your ValueChanged event handler in which you find the edited cell to change its value. You enumerate all cells in iGrid to find the edited cell, but there is a better, simpler and faster way. You can use the iGrid.CurCell property to retrieve the current cell which is currently being edited instead of your loops and the first If check for the sender. Does it work for you?
CDCDCD
2019-05-21T13:17:11Z
Yes, dead right about using iGrid.CurCell, my code wasn't very optimized (although my grid will have very few rows and columns so it shouldn't affect performance).
The only thing left is to make sure the event is only fired while the cell is being edited manually by the user, not when its value is modified programatically. Any hints?
Thanks again!
Igor/10Tec
2019-05-21T14:30:51Z
Originally Posted by: CDCDCD 

The only thing left is to make sure the event is only fired while the cell is being edited manually by the user, not when its value is modified programatically. Any hints?



Set a flag in your code before you change the cell value programmatically and clear it after this statement. Analyze whether this flag is set in your ValueChanged event handler and do or do not do the corresponding actions.