• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

Integrate a keystroke in datagridviewcombobox that is editable.

Hi Experts

I have a datagridview which has as its first column a datagridviewcombobox. This has been modifed to be editable.

I want to add an autocomplete subroutine that fires off keystrokes in the datagridviewcombobox.

Essentially I want to manage this via a keystoke event..

My issue is: Having pressed a key while in a combobox in the datagridview - how do I capture that keystroke? How do I test to see which combobox it is?

I thought using keyup for the datagridview but how do I know which combobox to work on.

Below is code similar to what I will use for autocomplete - but how to apply that to a combobox in a datagridview??

Simon
'This automatically manages autocomplete on the combobox its applied to.
    Public Sub autoComplete(ByRef cbx As ComboBox, ByRef e As System.Windows.Forms.KeyEventArgs) Implements clientINTERFACE.IfrmClientDisplay.autoComplete
 
        Try
 
            Select Case e.KeyCode
 
                Case Keys.Left, Keys.Right, Keys.Delete, Keys.End, Keys.Home, Keys.Up, Keys.Down
 
                    e.Handled = True
 
                    Return
 
                Case Keys.Tab, Keys.ShiftKey
 
                    If cbx.Text.Length > 0 Then
 
                        cbx.SelectionStart = 0
                        cbx.SelectionLength = cbx.Text.Length
 
 
 
                    End If
 
                    e.Handled = True
 
                    Return
 
            End Select
 
            Select Case e.KeyCode
 
                Case Keys.Back
 
                    If cbx.Text.Length = 0 Then
 
                        cbx.Text = ""
 
                        cbx.SelectionStart = 0
                        cbx.SelectionLength = cbx.Text.Length
 
                    End If
 
                    e.Handled = True
 
                    Return
 
            End Select
 
            Dim length = cbx.Text.Length
 
            If length > 0 Then
 
                Dim intIdx = cbx.FindString(cbx.Text)
 
                If intIdx >= 0 Then
 
                    cbx.SelectedIndex = intIdx
                    cbx.SelectionStart = length
                    cbx.SelectionLength = (cbx.Text).ToString.Length - length
 
                End If
 
            End If

Open in new window

0
si2030
Asked:
si2030
  • 3
  • 3
1 Solution
 
jpaulinoCommented:
You can capture in the form level.
Example:

    Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        
        If dgvCreditorInvoiceDetail.CurrentCellAddress.X = 0 Then
            Debug.WriteLine(e.KeyCode)
        End If
 
    End Sub

Open in new window

0
 
si2030Author Commented:
Hi jpaulino,

The event doesnt seem to fire when I type a series of characters...

http://www.screencast.com/users/si2030/folders/Jing/media/d4e20e84-026e-40c3-bed0-e9bf68df0dd4

Regards
Simon
0
 
jpaulinoCommented:
Do you have set Me.KeyPreview = True in the form ?
 
Off topic:
 Do you like jing for *.mp4 ? I only have used the free one to create *.swf and I like it but I'm also looking for mp4.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
si2030Author Commented:
Hi jpaulino

Perfect... that worked.

As for JING I only just discovered it a few weeks ago and love it. I am only using the free one also but as they say a picture is worth a 1000 words and in these instances I can explain to you far better using this method rather than some verbose written attempt...

I guess for $14.95 it allows you to do MP4 and higher quality - its not much money :)
0
 
jpaulinoCommented:
Glad I could help and thanks for the information :)
I also found it a few days ago and I'm testing it!
0
 
si2030Author Commented:
working with that last item..thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now