We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Integrate a keystroke in datagridviewcombobox that is editable.

si2030
si2030 asked
on
Medium Priority
208 Views
Last Modified: 2012-05-06
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

Comment
Watch Question

Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
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

Author

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
IT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008
Commented:
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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 :)
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
Glad I could help and thanks for the information :)
I also found it a few days ago and I'm testing it!

Author

Commented:
working with that last item..thanks
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.