dcsimg
Results 1 to 7 of 7

Thread: Combobox stays in blue once the focus is moved to other field?

  1. #1

    Thread Starter
    Addicted Member kutlesh's Avatar
    Join Date
    Jun 2018
    Location
    Skopje, Macedonia
    Posts
    195

    Combobox stays in blue once the focus is moved to other field?

    Not sure what is the problem here, I have few combo boxes which

    drop down style is DropDown,
    AutoCompleteMode is SuggestAppend
    AutoCompleteSource is ListItems

    Though I explicitly move the focus to other field, the ComboBox text is still in blue background and white text.
    What is happening here?

    Sample code:

    Code:
    Private Sub cboPrograma_KeyDown(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyEventArgs) Handles cboPrograma.KeyDown
            Dim KeyCode As Short = eventArgs.KeyCode
            Dim Shift As Short = eventArgs.KeyData \ &H10000
    
            If KeyCode = Keys.Left Then
                meOtsek.Focus()
            End If
        End Sub
    
        Private Sub cboPrograma_GotFocus(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cboPrograma.GotFocus
            cboPrograma.SelectAll()
        End Sub
    
        Private Sub cboPrograma_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cboPrograma.KeyUp
            If e.KeyCode = Keys.Left Or e.KeyCode = Keys.Right Then
                e.Handled = False
            ElseIf Convert.ToInt32(cboPrograma.Text) > 0 or Convert.ToInt32(cboPrograma.Text)  < 4 Then
                meDen.Focus()
            End If
        End Sub
    
        Private Sub cboPrograma_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPrograma.SelectedIndexChanged
            obrazecZaVnesRef.programa = vbNetUtilsDZS.convertToPositiveInteger(cboPrograma.Text)
        End Sub

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,723

    Re: Combobox stays in blue once the focus is moved to other field?

    I'm not sure whether it's related but you almost certainly shouldn't be calling Focus or handling GotFocus. If you read the relevant documentation you'll see that an application developer should generally be calling Select and handling Enter.

  3. #3

    Thread Starter
    Addicted Member kutlesh's Avatar
    Join Date
    Jun 2018
    Location
    Skopje, Macedonia
    Posts
    195

    Re: Combobox stays in blue once the focus is moved to other field?

    Didn't know that, but thanks for the advice.

    I should be using TabIndex and SendKeys to move trough the form?

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,450

    Re: Combobox stays in blue once the focus is moved to other field?

    I've had this problem but it's been so long ago I can't remember the exact situation. It might have been caused by trying to move between controls without using the Tab key, I'm just not sure. Anyway you could always just do this,

    Code:
    ComboBox1.SelectedText = Nothing

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,723

    Re: Combobox stays in blue once the focus is moved to other field?

    Quote Originally Posted by kutlesh View Post
    Didn't know that, but thanks for the advice.

    I should be using TabIndex and SendKeys to move trough the form?
    You should set up the Tab order as you want in any form. The user can then navigate by pressing the Tab key. If you want to advance to the next control via code then you call SelectNextControl.

  6. #6

    Thread Starter
    Addicted Member kutlesh's Avatar
    Join Date
    Jun 2018
    Location
    Skopje, Macedonia
    Posts
    195

    Re: Combobox stays in blue once the focus is moved to other field?

    By documentation, do you consider MSDN on WinForms? We have a CD of MSDN but I don't have it installed.
    Or you have some docs on this site about WinForms mechanism?
    Or maybe this https://docs.microsoft.com/en-us/dot...work/winforms/

    The application is for data entry. There are 40000 rows to be input. It should be optimized for fast data entry. That is why the day is a masked text box and not a numeric picker, and Tab key is replaced with Enter. Enter key is closer to the numeric keypad.

    And yes we are still collecting data using paper sadly...

    If the moderator could move this last post I wrote to this topic http://www.vbforums.com/showthread.p...39#post5439939
    Last edited by kutlesh; Dec 20th, 2019 at 02:49 AM.

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,723

    Re: Combobox stays in blue once the focus is moved to other field?

    Microsoft Docs has succeeded MSDN as the source for documentation on Microsoft development. As you're using an old version of VS, your MSDN documentation would still be valid, but it's probably easier to use the online Docs site. Whenever I want specifics regarding types or members, I always go straight to the API documentation:

    https://docs.microsoft.com/en-au/dot...tframework-4.8

    That defaults to .NET Framework 4.8 but you can modify the query string or remove it to default to all APIs.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width