For some reason there is sometimes no Value in the DataGridViewCell in CellEndEdit

Closed
0
0

Hello everyone,

I was using WiseJ Version 2.5.30 and updated now to WiseJ 3 because of this problem, but it persists. The error didn’t change.

So I’m working on a quite complex program and I’m trying to implement a way to see if a User changed a Cell, that has a Custom Editor.

The Custom Editor works properly. I’m subscribing to the event by Table.CellEndEdit += Tabelle_CellEndEdit;

The function looks something like this:

string name = Tabelle.Columns?[e.ColumnIndex]?.Name;
DataGridViewCell cell = Tabelle[e.ColumnIndex, e.RowIndex];

if (!String.IsNullOrEmpty(name))
{
    System.Diagnostics.Debug.WriteLine("Tabelle_CellEndEdit, name: " + name + ", Value: " + cell.Value);
    if(Tabelle.EditingControl is F3FeldEditor feldEditor)
    {
        System.Diagnostics.Debug.WriteLine("feldEditor.OldText: " + feldEditor.OldText + ", feldEditor.Text: " + feldEditor.Text);
    
        // Do other stuff
    }
}

The Debugger shows the following:

Tabelle_CellEndEdit, name: colPrjNr, Value: 20002
feldEditor.OldText: , feldEditor.Text: 20002

So this should work. If I now add a check to only do stuff when the Text changes, the Code looks like this:

string name = Tabelle.Columns?[e.ColumnIndex]?.Name;
DataGridViewCell cell = Tabelle[e.ColumnIndex, e.RowIndex];

if (!String.IsNullOrEmpty(name))
{
    System.Diagnostics.Debug.WriteLine("Tabelle_CellEndEdit, name: " + name + ", Value: " + cell.Value);
    if (Tabelle.EditingControl is F3FeldEditor feldEditor)
    {
        System.Diagnostics.Debug.WriteLine("feldEditor.OldText: " + feldEditor.OldText + ", feldEditor.Text: " + feldEditor.Text);
        
        if (feldEditor.OldText != feldEditor.Text)
        {
            // Do other stuff
        }
    }
}

But now the Debugger now shows the following, when I run it:

Tabelle_CellEndEdit, name: colPrjNr, Value: 
feldEditor.OldText: , feldEditor.Text: 20002

So for some reason the Cell has no Value any more, even though the Editor has the same Value. I changed nothing else in the Code and tested it for hours with the same Use Case. Did a CleanUp, deleted bin and obj folders, restarted VS2019 and the PC. It doesn’t make any sense that the Value disappears just because I have a check afterwards, but this is what’s happening. If I remove the Check and restart the program, the Value is there again.

Does anyone know why this is happening?

 

Edit: I found out that it is a little bit different. If I comment out all the “Do other stuff” I never have a cell-value. When is the Cell Value copied from the Editor to the Cell?

  • You must to post comments
0
0

Update: I rewrote my Editor. It now extends DataGridViewTextBoxEditingControl. Before it only derived from TextBox and I think that was an issue. Now it seems to work properly.

  • You must to post comments
0
0

Hi Sascha,

Can you please wrap up a small sample with your custom editor included?
I couldn’t reproduce the issue!

Thanks,
Alaa

//

  • You must to post comments
Showing 2 results