How Can i detect return key in datagridTextBoxColumn
-
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 key. 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.ContextMenu = ContextMenu1 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... ***
-
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 key. 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.ContextMenu = ContextMenu1 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... ***
The return key is captured to end edits. If you begin editing a
DataGridTextBoxColumn
and then press enter the edit will end. If you want to override this you'll have to be really careful or edits or use the column as read-only. The easiest (maybe only) way to do this would be to creat your own wrapper which inherits theDataGridTextBoxColumn
class. Eg:Public Class DataGridTextBoxSelectorColumn Inherits DataGridTextBoxColumn Public ... End Class
From here you should be able to override the key events. Be careful that if your not going to actually do anything on the event that you call the equivalent MyBase.whatever event. Tatham Oddie (VB.NET/C#/ASP.NET/VB6/ASP/JavaScript) tatham@e-oddie.com +61 414 275 989 -
The return key is captured to end edits. If you begin editing a
DataGridTextBoxColumn
and then press enter the edit will end. If you want to override this you'll have to be really careful or edits or use the column as read-only. The easiest (maybe only) way to do this would be to creat your own wrapper which inherits theDataGridTextBoxColumn
class. Eg:Public Class DataGridTextBoxSelectorColumn Inherits DataGridTextBoxColumn Public ... End Class
From here you should be able to override the key events. Be careful that if your not going to actually do anything on the event that you call the equivalent MyBase.whatever event. Tatham Oddie (VB.NET/C#/ASP.NET/VB6/ASP/JavaScript) tatham@e-oddie.com +61 414 275 989Hi Tatham, Thank you for your help. I tried your code bu it doesn't work. if you can clarify more. I attract your attention that the return key is completely omitted in the datagrid and all the other keys work correctly. Probably because key appears in the list of keyboard shortcut of the datagrid control thank you for advance. intibnin ***
-
Hi Tatham, Thank you for your help. I tried your code bu it doesn't work. if you can clarify more. I attract your attention that the return key is completely omitted in the datagrid and all the other keys work correctly. Probably because key appears in the list of keyboard shortcut of the datagrid control thank you for advance. intibnin ***
Sorry, I cant really help much more. I dont have any other ideas. Tatham Oddie (VB.NET/C#/ASP.NET/VB6/ASP/JavaScript) tatham@e-oddie.com +61 414 275 989