Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How Can i detect return key in datagridTextBoxColumn

How Can i detect return key in datagridTextBoxColumn

Scheduled Pinned Locked Moved Visual Basic
workspacecssalgorithmssalesregex
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    intibnin
    wrote on last edited by
    #1

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

    T 1 Reply Last reply
    0
    • I 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... ***

      T Offline
      T Offline
      Tatham
      wrote on last edited by
      #2

      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 the DataGridTextBoxColumn 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

      I 1 Reply Last reply
      0
      • T Tatham

        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 the DataGridTextBoxColumn 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

        I Offline
        I Offline
        intibnin
        wrote on last edited by
        #3

        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 ***

        T 1 Reply Last reply
        0
        • I 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 ***

          T Offline
          T Offline
          Tatham
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups