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

inserting CR when user types ALT-ENTER

Thread ID:

Created:

Updated:

Platform:

Replies:

39532 Jan 10,2006 05:27 PM UTC Jan 20,2006 12:12 PM UTC WinForms 6
loading
Tags: GridControl
Eric Weber
Asked On January 10, 2006 05:27 PM UTC

Similar to Excel, when a user is editing a cell in a GGC, how can I get the ALT-ENTER keystroke combination to insert a carriage return? thanks! Eric

stanleyj [Syncfusion]
Replied On January 11, 2006 08:19 AM UTC

Hi Eric, You need to have a custom engine that supports saving row heights. The custom engine allows resizing of rows independent to know more on that refer the sample in :\Program Files\Syncfusion\Essential Studio\4.1.0.10\windows\Grid.Grouping.Windows\Samples\ResizableRows. The custom engine should be added this way in the form''s ctor before InitializeComponent call. GridEngineFactory.Factory = new GroupingEngineFactory(); Then using TableControlCurrentCellActivated and QueryCellStyleInfo setting these properties mentioned in the code snippet below you can use Enter key to create a new line within a cell. private void gridGroupingControl1_TableControlCurrentCellActivated(object sender, GridTableControlEventArgs e) { e.TableControl.AllowTextBoxAutoSize = true; e.TableControl.WantEnterKey = false; } private void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e) { e.Style.AutoSize = true; e.Style.AllowEnter = true; } Best regards, Stanley

Eric Weber
Replied On January 11, 2006 05:19 PM UTC

Thanks for the advice Stanley. My grid is already using syncfusion''s custom row height engine, and I have already experimented with WantEnterKey and AllowEnter. Here''s what I''ve noticed so far, and why I asked the question... In my editable GGC (without doing any special coding) if I am editing a cell and then press the ENTER key, the cell editing ends. This is great...just like Excel...so far so good. If I implement WantEnterKey and AllowEnter, then, as you said, I''ll be able to enter blank lines into the cell when I press the ENTER key. But then how does the user end their cell editing session (w/o touching the mouse)? Just like with Excel, I want ALT-ENTER to add blank lines to a cell, not ENTER. ENTER should be used for ending cell editing. Thanks! eric

stanleyj [Syncfusion]
Replied On January 12, 2006 04:52 PM UTC

Hi Eric, It is not that necessary to use a mouse interaction to come out of the cell. Tab, Shift+Tab or the arrow keys also helps in navigating and there by ends the editing. I will also update this thread if a sample could be made working with Alt+Enter. Regards, Stanley

stanleyj [Syncfusion]
Replied On January 12, 2006 04:52 PM UTC

Hi Eric, It is not that necessary to use a mouse interaction to come out of the cell. Tab, Shift+Tab or the arrow keys also helps in navigating and there by ends the editing. I will also update this thread if a sample could be made working with Alt+Enter. Regards, Stanley

Eric Weber
Replied On January 20, 2006 01:31 AM UTC

Why won''t something like this work? But instead of inserting a "hello", I could enter a new line. private void TableControl_CurrentCellKeyDown(object sender, KeyEventArgs e) { if (e.Alt == true && e.KeyCode == Keys.Enter) { GridCurrentCell cc = this.TableControl.CurrentCell; TextBoxBase tb = ((GridTextBoxCellRenderer)cc.Renderer).TextBox; tb.Text.Insert(0, "hello"); } } And unfortunately this code doesn''t work, why not? What am i missing? Replacing the last line with tb.SelectAll() works just fine. Thanks! eric

stanleyj [Syncfusion]
Replied On January 20, 2006 12:12 PM UTC

Hi Eric, This works for me. this.gridGroupingControl1.TableControlCurrentCellKeyDown += new GridTableControlKeyEventHandler(gridGroupingControl1_TableControlCurrentCellKeyDown); private void gridGroupingControl1_TableControlCurrentCellKeyDown(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlKeyEventArgs e) { if((Control.ModifierKeys & Keys.Alt) != 0 && e.Inner.KeyCode == Keys.Enter) { Console.WriteLine("alt+enter"); e.Inner.Handled = true; GridCurrentCell cc = this.gridGroupingControl1.TableControl.GetNestedCurrentCell(); TextBoxBase tb = cc.Renderer.Control as TextBoxBase; if(tb != null) { tb.SelectedText = Environment.NewLine; cc.BeginEdit(); this.gridGroupingControl1.TableModel.RowHeights[cc.RowIndex] += 17; } } } Here is a sample. Best regards, Stanley

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

;