We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Problems with multiline editing in cells

Thread ID:

Created:

Updated:

Platform:

Replies:

52371 Nov 27,2006 08:28 PM UTC Dec 11,2006 01:30 PM UTC WinForms 8
loading
Tags: GridControl
Maxim Software Systems
Asked On November 27, 2006 08:28 PM UTC

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.)

Administrator [Syncfusion]
Replied On 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

Maxim Software Systems
Replied On 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?

Maxim Software Systems
Replied On 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?

Administrator [Syncfusion]
Replied On 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

Maxim Software Systems
Replied On 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.


Administrator [Syncfusion]
Replied On 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

Maxim Software Systems
Replied On 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)

Administrator [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;