SourceGrid cell change by Enter key press

Apr 18, 2009 at 4:20 PM

Hi ppl

I cant change the cell focus by Entering key Enter.

That Means I want to add info to a cell and press enter key to go another cell.

Can anyone help me a lil detail because Im totally new in sourceGrid.


Apr 19, 2009 at 3:41 PM
Ok, i've never done this myself before, so i've tried to modify sample 17 to do what you want.

What you need to do is add a controller to each cell, and override on key down event.

here's how i did it:

    CustomEvents events = new CustomEvents();
            events.KeyDown += delegate(object eventSender, KeyEventArgs kargs)
                if (kargs.KeyCode != Keys.Enter)
                Position position = grid1.Selection.ActivePosition;
                ICell cell = grid1[position.Row, position.Column];
                if (cell.Editor.IsEditing == true)
                     cell.Editor.ApplyEdit(); else
                grid1.Selection.Focus(new Position(position.Row + 1 , position.Column), true);
            Random rnd = new Random();
            for (int r = 1; r < grid1.RowsCount; r++)
                grid1[r,0] = new SourceGrid.Cells.RowHeader("Header " + r.ToString());
                for (int c = 1; c < grid1.ColumnsCount; c++)
                    if (rnd.NextDouble() > 0.20)
                        grid1[r,c] = new SourceGrid.Cells.Cell(r*c, typeof(int));
                        grid1[r,c] = null;

If there's better way to do this, please let me know :)

Apr 19, 2009 at 4:06 PM

Too hard for me to understand the code...

Im trying to use it. 

Thanks dariusdamalakas for your Effort.

Apr 20, 2009 at 11:32 PM

sorry didnt workout


Apr 21, 2009 at 4:40 PM
The sample did not work?
Apr 21, 2009 at 11:58 PM

I cant make it work in my project...dont know why.

Can you explain a lil bit more where acjactly I will use this code?


Apr 25, 2009 at 8:00 AM
Well, the main idea is to attach a controller to cell, so that it handles enter key event.

a controller is handling KeyDown  event, and if it's key enter, moves the active cell focus by one row downwards