Strange combo box behavior

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J L

    #1

    Strange combo box behavior

    I am trying to use the following code to auto fill a combo box
    (credit and thanks to Code Project and Daryl)


    Public Sub AutoFillCombo(B yVal theCombo As ComboBox, ByVal theKey As
    Keys)
    Dim sTypedText As String
    Dim iFoundIndex As Integer
    Dim oFoundItem As Object
    Dim sFoundText As String
    Dim sAppendText As String

    Select Case theKey
    Case Keys.Back, Keys.Left, Keys.Right, Keys.Delete, Keys.Down
    Return
    End Select

    With theCombo
    sTypedText = .Text
    iFoundIndex = .FindString(sTy pedText)
    If iFoundIndex >= 0 Then
    oFoundItem = .Items(iFoundIn dex)
    sFoundText = .GetItemText(oF oundItem)
    sAppendText = sFoundText.Subs tring(sTypedTex t.Length)
    .Text = sTypedText & sAppendText
    .SelectionStart = sTypedText.Leng th
    .SelectionLengt h = sAppendText.Len gth
    End If
    End With
    End Sub

    The problem is this: If I have the name John in my combo box and type
    in john (that is, using a small letter j not J), it automatically
    fills the box with the John not john. I checked sTypedText just before
    the .Text assignment and it is small letter j. So when .Text is set,
    it seems to find the John entry and uses it..or something...wha t am I
    missing here?

    TIA,
    John

  • J L

    #2
    Re: Strange combo box behavior

    Opps, Just read further and see that the FindString search is not case
    sensitive!

    John

    n Sun, 08 May 2005 07:45:57 -0700, J L <john@marymonte .com> wrote:
    [color=blue]
    >I am trying to use the following code to auto fill a combo box
    >(credit and thanks to Code Project and Daryl)
    >
    >
    >Public Sub AutoFillCombo(B yVal theCombo As ComboBox, ByVal theKey As
    >Keys)
    > Dim sTypedText As String
    > Dim iFoundIndex As Integer
    > Dim oFoundItem As Object
    > Dim sFoundText As String
    > Dim sAppendText As String
    >
    > Select Case theKey
    > Case Keys.Back, Keys.Left, Keys.Right, Keys.Delete, Keys.Down
    > Return
    > End Select
    >
    > With theCombo
    > sTypedText = .Text
    > iFoundIndex = .FindString(sTy pedText)
    > If iFoundIndex >= 0 Then
    > oFoundItem = .Items(iFoundIn dex)
    > sFoundText = .GetItemText(oF oundItem)
    > sAppendText = sFoundText.Subs tring(sTypedTex t.Length)
    > .Text = sTypedText & sAppendText
    > .SelectionStart = sTypedText.Leng th
    > .SelectionLengt h = sAppendText.Len gth
    > End If
    > End With
    >End Sub
    >
    >The problem is this: If I have the name John in my combo box and type
    >in john (that is, using a small letter j not J), it automatically
    >fills the box with the John not john. I checked sTypedText just before
    >the .Text assignment and it is small letter j. So when .Text is set,
    >it seems to find the John entry and uses it..or something...wha t am I
    >missing here?
    >
    >TIA,
    >John[/color]

    Comment

    • J L

      #3
      Re: Strange combo box behavior

      Double opps...the case sensitive search still does not explain why the
      ..Text seems to convert the sTypedText to upper case...so mystery
      continues...

      John

      On Sun, 08 May 2005 07:45:57 -0700, J L <john@marymonte .com> wrote:
      [color=blue]
      >I am trying to use the following code to auto fill a combo box
      >(credit and thanks to Code Project and Daryl)
      >
      >
      >Public Sub AutoFillCombo(B yVal theCombo As ComboBox, ByVal theKey As
      >Keys)
      > Dim sTypedText As String
      > Dim iFoundIndex As Integer
      > Dim oFoundItem As Object
      > Dim sFoundText As String
      > Dim sAppendText As String
      >
      > Select Case theKey
      > Case Keys.Back, Keys.Left, Keys.Right, Keys.Delete, Keys.Down
      > Return
      > End Select
      >
      > With theCombo
      > sTypedText = .Text
      > iFoundIndex = .FindString(sTy pedText)
      > If iFoundIndex >= 0 Then
      > oFoundItem = .Items(iFoundIn dex)
      > sFoundText = .GetItemText(oF oundItem)
      > sAppendText = sFoundText.Subs tring(sTypedTex t.Length)
      > .Text = sTypedText & sAppendText
      > .SelectionStart = sTypedText.Leng th
      > .SelectionLengt h = sAppendText.Len gth
      > End If
      > End With
      >End Sub
      >
      >The problem is this: If I have the name John in my combo box and type
      >in john (that is, using a small letter j not J), it automatically
      >fills the box with the John not john. I checked sTypedText just before
      >the .Text assignment and it is small letter j. So when .Text is set,
      >it seems to find the John entry and uses it..or something...wha t am I
      >missing here?
      >
      >TIA,
      >John[/color]

      Comment

      • Ken Tucker [MVP]

        #4
        Re: Strange combo box behavior

        Hi,

        Here is a sample that works really well.


        Ken
        -------------------
        "J L" <john@marymonte .com> wrote in message
        news:t29s719ojn fimia8b7jlbnlrq q2ptpalqi@4ax.c om...
        I am trying to use the following code to auto fill a combo box
        (credit and thanks to Code Project and Daryl)


        Public Sub AutoFillCombo(B yVal theCombo As ComboBox, ByVal theKey As
        Keys)
        Dim sTypedText As String
        Dim iFoundIndex As Integer
        Dim oFoundItem As Object
        Dim sFoundText As String
        Dim sAppendText As String

        Select Case theKey
        Case Keys.Back, Keys.Left, Keys.Right, Keys.Delete, Keys.Down
        Return
        End Select

        With theCombo
        sTypedText = .Text
        iFoundIndex = .FindString(sTy pedText)
        If iFoundIndex >= 0 Then
        oFoundItem = .Items(iFoundIn dex)
        sFoundText = .GetItemText(oF oundItem)
        sAppendText = sFoundText.Subs tring(sTypedTex t.Length)
        .Text = sTypedText & sAppendText
        .SelectionStart = sTypedText.Leng th
        .SelectionLengt h = sAppendText.Len gth
        End If
        End With
        End Sub

        The problem is this: If I have the name John in my combo box and type
        in john (that is, using a small letter j not J), it automatically
        fills the box with the John not john. I checked sTypedText just before
        the .Text assignment and it is small letter j. So when .Text is set,
        it seems to find the John entry and uses it..or something...wha t am I
        missing here?

        TIA,
        John


        Comment

        • Cor Ligthert

          #5
          Re: Strange combo box behavior

          JL,

          I was making a new sample for you yesterday, the one you use now has in my
          idea needles to much sentences, I did not succeed directly and had to go,
          however I see now that Ken supplied one. Your problem is probably that Jonh
          is found in the items, and replaces that in the textbox (what it should do).

          Cor


          Comment

          Working...