This project is read-only.

Cell doesn't accept input. OnValueChanging trouble

Jun 15, 2012 at 1:38 PM

I,ve created grid with text cells:

var cell = new SG.Cells.Cell( string.Empty, typeof( string ) );

Controller to format input:

internal class ValueChangedEvent : SG.Cells.Controllers.ControllerBase
{
    public override void OnValueChanging( SG.CellContext sender, SG.ValueChangeEventArgs e )
    {
        base.OnValueChanging( sender, e );

        // Doesn't work!
        e.NewValue = '(' + e.OldValue.ToString() + ')';

        // It's ok!
        //e.NewValue = 5;
    }
}

grid.Controller.AddController( new ValueChangedEvent() );

But when I enter symbols in cell and press "return" nothing happens. Cell doesn't accept input. OnValueChanging event doesn't fire. I cannot go to another cell. Only if I press "Escape" cell closes for input.

At the same time if I change code to e.NewValue = 5 it's work!

What's problem?

Jun 16, 2012 at 2:04 AM
Edited Jun 16, 2012 at 2:06 AM

Simple project:

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SG = SourceGrid;

namespace ExploreSourceGrid4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load( object sender, EventArgs e )
        {
            grid.Redim( 10, 2 );
            for( int r = 0; r < grid.RowsCount; r++ )
            {
                for( int c = 0; c < grid.ColumnsCount; c++ )
                {
                    grid[r, c] = new SG.Cells.Cell( string.Empty, typeof( string ) );                    
                }    
            }
            grid.Controller.AddController( new ValueChangedEvent() );
        }
    }

    public class ValueChangedEvent : SG.Cells.Controllers.ControllerBase
    {
        public override void OnValueChanging( SG.CellContext sender, SG.ValueChangeEventArgs e )
        {
            base.OnValueChanging( sender, e );

            e.NewValue = '(' + e.OldValue.ToString() + ')';
            // This works!
            //e.NewValue = 5;
        }
    }        
}

 

Doesn't work. I don't understand....

Jun 18, 2012 at 11:12 AM

Your code is failing with NullRef exception, since you are calling e.OldValue is null.