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

How can i catch a return key from datagridtextboxcolumn

Thread ID:

Created:

Updated:

Platform:

Replies:

2321 Jan 6,2003 11:57 AM UTC Jan 8,2003 07:23 AM UTC Windows Forms 1
loading
Tags: FAQ
intibnin
Asked On January 6, 2003 11:57 AM UTC

Hi, Please I need help. I created a form that allows me searching customers by name. after display customers list in datagrid, i want allow user to select one customer by pressing return key (chr(13)). for grid setup, i tried the following code : 'Configuration de la grille Private Sub DataGridSetup() Dim ts As New DataGridTableStyle() Dim cs As New DataGridTextBoxColumn() AddHandler cs.TextBox.KeyPress, AddressOf CellKeyPress DataGrid1.CaptionText = "Résultat" ts.MappingName = "mycli" cs.MappingName = "c_cli" cs.HeaderText = "Code" cs.Alignment = HorizontalAlignment.Center ts.GridColumnStyles.Add(cs) cs = New DataGridTextBoxColumn() cs.MappingName = "N_cli" cs.HeaderText = "Nom/Raison sociale" ts.GridColumnStyles.Add(cs) DataGrid1.TableStyles.Clear() DataGrid1.TableStyles.Add(ts) End Sub and i added handler to datagridtextboxcolumn, for detecting the keypress events as follows : 'Ajout d'un évènement aux cellules Public Sub CellKeyPress(ByVal Sender As Object, ByVal e As KeyPressEventArgs) Dim dt As DataTable = ds.Tables("mycli") Dim p As Integer CodeClient = Space(11) If e.KeyChar = Chr(13) Then p = Me.BindingContext(ds, "mycli").Position CodeClient = dt.Rows(p)("c_cli") Me.Close() End If End Sub So after writing this code, i can select one customer only after pressing SHIFT+RETURN. please can you explain me way i must first press SHIFT. Thank you very match. Intibnin...

Administrator [Syncfusion]
Replied On January 8, 2003 07:23 AM UTC

I think that the grid must be catching the enter key and not passing it onto the embedded textbox control. You can catch this enter key without using columnstyles by deriving the DataGrid and overriding ProcessKeyPreview.
Public Class MyDataGrid
	Inherits DataGrid
    
	Private Const WM_KEYDOWN As Integer = &H100
	Private Const WM_KEYUP As Integer = &H101
    
    
	Protected Overrides Function ProcessKeyPreview(ByRef m As System.Windows.Forms.Message) As Boolean
		Dim keyCode As Keys = CType(m.WParam.ToInt32(), Keys) And Keys.KeyCode
		If m.Msg = WM_KEYDOWN OrElse m.Msg = WM_KEYUP AndAlso keyCode = Keys.Enter Then
			Console.WriteLine("grid Keys.Enter")
			' return false; 'ignore
		End If 
		Return True
	End Function 'ProcessKeyPreview
End Class 'MyDataGrid

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

;