vb-dev
2023-02-15T21:19:02Z
The TextBoxTextChanged event fires when using the mouse to click into a cell. Is there a way to prevent this and cause it to fire only when the user actually changes the text in the TextBox? Thank you.

Igor/10Tec
2023-02-16T15:55:43Z
Let's consider how editing in iGrid works. When the user puts the current cell into edit mode, we place an edit control (.NET TextBox in the default case) over the current cell, attach event handlers including TextChanged, pass the cell text to the editor, and finally set the input focus to it. The editor's TextChanged even handler is linked to iGrid's TextBoxTextChanged event. This explains why the TextBoxTextChanged event is fired when editing is started.

We can change this behavior and suppress the first TextBoxTextChanged event using an internal Boolean flag or another trick, but the question is whether we should do this. iGrid's TextBoxTextChanged event works like the TextChanged event in a TextBox control - the TextChanged event is raised when you change the text in the control.

Can you tell us more about your situation in which you need the requested change?
vb-dev
2023-02-16T17:07:45Z
Thank you for your reply.

The TextBoxChanged event is raised both when the TextBox receives its value from the underlying cell, and when the user changes the text in the TextBox.

I understand the mechanics and understand that the event is raised when editing is started because the TextBox receives the value from the cell, and is indeed changed. But that value is the current value from the cell, which has not been changed. It is only truly "changed" when it is edited in the TextBox. I guess I expected that the event would be suppressed (or be suppressible) when the TextBox receives its value from the underlying cell. There may well be situations in which being able to respond to that initial event firing is important. I'm not sure. At any rate, the situation is that I'm just trying to implement row-based editing in an iGrid, in which the user is prevented from changing rows when the current row is not valid (is dirty).

I have today been experimenting with ways to suppress (actually, ignore) the initial event. The following seems to serve the purpose, so far. If you could comment on this idea I would appreciate it.
iGrid.CellValue(Of T) is an extension method.

    Private Sub UserAdminGrid_TextBoxTextChanged(sender As Object, e As iGTextBoxTextChangedEventArgs) Handles UserAdminGrid.TextBoxTextChanged
        Dim text = UserAdminGrid.TextBox.Text
        Dim value = UserAdminGrid.CellValue(Of String)(e.RowIndex, e.ColIndex)

        If Not text.Equals(value) Then
            rowDirty = True
            Call ManageControls()
        End If
    End Sub

Igor/10Tec
2023-02-17T15:42:57Z
If we take the behavior of the TextBox control as a reference, we may look at the situation from the following point of view. Putting an iGrid cell into edit mode is like moving the input focus to a TextBox containing text. Will the TextBox fire the TextChange event at that? Definitely not.

I don't mind changing the iGrid behavior, but I must be sure the change is what others will welcome. I think, I need to hear opinions of other developers.

Regarding your solution. It is very self-descriptive and clearly indicates your intention. If the task was to suppress the first TextBoxTextChanged event, perhaps, personally I would use a Boolean flag and clear/set it in event handlers of the AfterCommitEdit and CancelEdit events, which finish every cell editing process (either of them depending on the result). But if we think about your task, this is not what you need. What you exactly need is to make the current row dirty only if the edited cell text differs from the original value. In the case of subsequent TextBoxTextChanged events you would always mark the row as dirty regardless of the currently entered text.
vb-dev
2023-02-17T17:14:24Z
I'm still working on this, but it seems comparing the TextBox.Text with the value of the current cell is sufficient when there is a need to suppress the unwanted event. So I'm not requesting that any modification be made. I'm still exploring the iGrid's events. From what I can see, however, you have implemented events that allow us to support both cell-based and row-based editing. This first attempt is row-based. We will soon do cell-based editing as well and I think a Boolean flag managed in the AfterCommitEdit and CancelEdit events will be fine. I note there are at least two demo projects that demonstrate this. Thank you for sharing that suggestion.

Angelos
2023-03-07T07:49:12Z
Hello vb-dev,
Honesty I never used the TextBoxChanged Event, but I think I understand what you want to do.
The scenario is that the cell have a value and you want to do something when the this value is changed.
For this I use the BeforeCommitEdit and AfterCommitEdit events as following:
1. There is a global variable geting the cell value of the current cell using the BeforeCommitEdit event.
2. The After CommitEdit event compare the values before and after.

Here's an example of how I do this.

Dim beforeData as String = ""

Private Sub IGrid1_BeforeCommitEdit(sender As Object, e As iGBeforeCommitEditEventArgs) Handles IGrid1.BeforeCommitEdit
        beforeData = IGrid1.CurCell.Value
End Sub

Private Sub IGrid1_AfterCommitEdit(sender As Object, e As iGAfterCommitEditEventArgs) Handles IGrid1.AfterCommitEdit
        If IGrid1.CurCell.Value <> beforeData Then
            'do something
        End If
End Sub

Maybe this is not the best solution, but it is tested with huge grids of over 5000 rows and it works great.
I hope this will help 🙂
vb-dev
2023-03-16T17:02:11Z
Thank you Angelos for presenting an alternate method for achieving this.