)
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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to restrict the multiline text insertion behavior in WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: April 19, 2015 |
Last Revised Date: December 20, 2019
Tags: keyhandling

Restrict the multiline insertion

To disable the multiline insertion on pressing Crtl+Enter in the OriginalTextBox cell, the CurrentCellKeyPress and CurrentCellKeyDown events are handled.

C#

bool disable_multiline = true;
void gridControl1_CurrentCellKeyPress(object sender, KeyPressEventArgs e)
{
    if ((Control.ModifierKeys & Keys.Control) != 0 && e.KeyChar.ToString() == "\n")
    {
        if (disable_multiline) //to check whether to disable or enable the insertion
        {                   
            e.Handled = true;
        }
    } 
}
void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
    if ((Control.ModifierKeys & Keys.Control) != 0 && e.KeyCode == Keys.Enter)
    {
                       if (disable_multiline)
        {                   
            // Disabling multiline insertion.
            e.Handled = true;
        }
    }
}
// disable_multiline bool value assigned in button click.
private void EnableBtn_Click(object sender, EventArgs e)
{
    disable_multiline = false;
}
private void DisableBtn_Click(object sender, EventArgs e)
{
    disable_multiline = true;
}

 

VB

Private disable_multiline As Boolean = True
Private Sub gridControl1_CurrentCellKeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
 If (Control.ModifierKeys And Keys.Control) <> 0 AndAlso e.KeyChar.ToString() = Constants.vbLf Then
  If disable_multiline Then 'to check whether disable or enable the insertion
   e.Handled = True
  End If
 End If
End Sub
Private Sub gridControl1_CurrentCellKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
 If (Control.ModifierKeys And Keys.Control) <> 0 AndAlso e.KeyCode = Keys.Enter Then
  If disable_multiline Then
   e.Handled = True
  End If
 End If
End Sub
' disable_multiline bool value assigned in button click.
Private Sub EnableBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
 disable_multiline = False
End Sub
Private Sub DisableBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
 disable_multiline = True
End Sub

 

Samples:

C#: MultiLineInsertion-C#

VB: MultiLineInsertion-VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

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

Live Chat Icon For mobile
Live Chat Icon