This project is read-only.

Empty Cells (decimal) instead of zero

Jul 31, 2009 at 1:01 PM


I am trying to build a table with the SourceGrid.

Now I made a decimal column with cells in my grid like this:

grid1[i, 1] = new SourceGrid.Cells.Cell("", typeof(decimal));
grid1[i, 1].View = cellStyle;

So i've got a few empty Cells now.

Now my problem is, that the SourceGrid does not allow me to "delete" a Value in a Cell. It has to be 0.
But I don't want to have a 0 in all my cells.

When I enter the cells edit-mode and delete the Value in it (or if the cell was empty and I do nothing in editmode) I will not get out of the edit mode.

Only if I type a "0" i can press Enter and leave the edit mode.

Please help.
I want to look for an empty sender.Value in my OnEditEndet Event to do something.

Thanks alot,

Best regards

Aug 7, 2009 at 1:17 PM

I think you will be able to have a "" if you use a CellEditor and set the "AllowNull" property to true.

But the problem of "0" when the user presses [Del] key will still remain. If you don't want it you'll have the manage the event yourself:

- remove SourceGrid.ClipboardMode.Delete from mygrid.ClipboardMode
- add a Controller and catch KeyPress event



        public class KeyEvent : SourceGrid.Cells.Controllers.ControllerBase
            public KeyEvent()

            public override void OnKeyDown(SourceGrid.CellContext sender, KeyEventArgs e)
                base.OnKeyDown(sender, e);

                // Delete selected cells
                if (e.KeyCode == Keys.Delete)
                    // Set here the cell value to null or what you want