Problems with multiline editing in cells

When entering text into a GridControl Textbox-style cell whose AllowEnter property has been set to True, it appears that the Enter key inserts only a "line feed" character (ASCII 10) instead of a "carriage return & line feed" character pair (ASCII 13 & 10). Is there anyway to change this behavior?

(FYI, I'm using v3.301 of the SyncFusion grid.)

8 Replies

AD Administrator Syncfusion Team November 28, 2006 05:30 AM UTC

Hi Don,

To change the behavior of the Enter key, you can handle the CurrentCellKeyDown event and use the SendKeys.Send() method to send the keystroke the currentcell. Here is a code snippet

bool IsManualEnterKey = false;
private void gridControl1_CurrentCellKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if( e.KeyData == Keys.Enter && IsManualEnterKey)
{
//Cancel the default EnterKey behaviour...
e.Handled = true;
IsManualEnterKey = true;
SendKeys.Send("{YOU_KEY_HERE}");
IsManualEnterKey = false;
}
}

Best Regards,
Haneef


MS Maxim Software Systems November 28, 2006 01:15 PM UTC

I tried the code example you posted, tweaking it a bit to get it to work, but it behaves the same way. I even tried sending a Ctrl-Enter, but that made no difference. It seems to me that this technique is just emulating the Enter keypress on the keyboard, which is exactly what I was doing already. The problem seems to be that the grid cell was treating the Enter key as a linefeed character instead of a carriage-return character, whether it receives it programatically via SendKeys or manually via the keyboard.

Also (this is in addition to the problem I mentioned in my first post) when I try to put a string that contains a CRLF character pair in the cell, it doesn't put a line break in the text when it displays it, either.

Am I going to have to do some sort of string conversion everytime I want to read text from or write text to a grid cell?


MS Maxim Software Systems December 1, 2006 03:33 PM UTC

So, is there anything I can do about this issue short of manually replacing CRLF characters with LFcharacters, and vice versa, when reading a multiline string to and from a cell?


AD Administrator Syncfusion Team December 4, 2006 07:27 AM UTC

Hi Don,

You can use the Renderer.ControlText property to append the 'LineFeed' character while pressing the 'Enter' key in a grid cell. Please try the below code snippet to resolve this.

private void gridControl1_CurrentCellKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
GridControl grid = sender as GridControl;
if( e.KeyData == Keys.Enter && IsManualEnterKey)
{
//Cancel the default EnterKey behaviour...
e.Handled = true;
object obj = grid.CurrentCell.Renderer.GetEditState();
grid.CurrentCell.Renderer.ControlText += "\n";
grid.CurrentCell.Renderer.SetEditState(obj);
}
}

Best Regards,
Haneef


MS Maxim Software Systems December 4, 2006 11:45 AM UTC

I think there's still some confusion here. The problem I'm having is that the grid cell is not recognizing the carriage return character properly.

If I set a string with a carriage return in it into the cell, the cell will not display the line break. Furthermore, when I press the Enter key in the cell, the cell inserts a linefeed character instead of a carriage return character or linefeed-carraige return character pair.



AD Administrator Syncfusion Team December 6, 2006 10:00 AM UTC

Hi Don,

Try setting the CellType of the cell to "OriginalTextBox" in a grid. Please refer to the attached sample and let me know if this helps.

Sample : GC_SelectionTest.zip

Best Regards,
Haneef


MS Maxim Software Systems December 6, 2006 02:26 PM UTC

Changing the CellType to "OriginalTextBox" did the trick. Thanks!

One more question, though: is it possible to insert new lines by just pressing Enter instead of Ctrl-Enter? (FYI, In case you included it in your sample code, I don't have C# installed)


AD Administrator Syncfusion Team December 11, 2006 01:30 PM UTC

Hi Don,

If you want to handle the "Ctrl+Enter" Key stroke in a grid cell, you need to handle the CurrentCellControlKeyMessage event of the grid. Here is a code snippet to show this.

private void gridControl1_CurrentCellControlKeyMessage(object sender, GridCurrentCellControlKeyMessageEventArgs e)
{
Keys keyCode = (Keys)((int)e.Msg.WParam) & Keys.KeyCode;
if (keyCode==Keys.Enter && ((Control.ModifierKeys & Keys.Control)!=0))
{
e.Handled = true;
e.CallProcessKeyPreview = false;
e.CallBaseProcessKeyMessage = false;
}
}

Here is a sample.
GCControlEnterKey.zip

Best Regards,
Haneef

Loader.
Up arrow icon