[Gambas-user] Auto select item in new combobox

Safiur Rahman isafiur at gmail.com
Mon Feb 6 08:41:44 CET 2023


Thanks Lee for your quick response. It solved the key down problem.

I was thinking of ComboBox with additional native features like
1) Select the first matching item as user writes into ComboBox (as above)
2) Restrict to own items: The user is stopped from writing any string in
ComboBox which does not match to any item.
3) user can write in ComboBox after pop up list is displayed and popup list
is sorted as user writes more alphabet.

Any help would be appreciated.

On Sun, 5 Feb 2023, 15:01 Safiur Rahman, <isafiur at gmail.com> wrote:

> Hi
>
> I used the following code to auto fill text in Combobox. This worked
> well upto gambas 3.17.3.
>
> 1) Type any alphabet and the related word is shown in combobox. This
> works fine in gambas 3.18.0
>
> 2) Press down arrow to open pop up list and then type any alphabet.
> The related word is selected. Upto this step gambas 3.18.0 works fine.
> But when I press Return/Enter key then selected item is not returned
> in gambas 3.18.0 (but worked fine till 3.17.3).
>
> Requesting for improvement in the current code.
>
> Public Sub Form_Open()
>
>   ComboBoxItems.List = ["aaa", "bbb", "ccc", "ddd", "eee", "fff"]
>
> End
>
> Public Sub ComboBoxItems_KeyRelease()
>
>   Dim i As Integer
>   Dim textToCursor As String
>   Dim textPosition As Integer
>
>   If Key.Code = Key.Down Then
>     textPosition = ComboBoxItems.Pos
>     textToCursor = Mid(ComboBoxItems.Text, 1, textPosition)
>     ComboBoxItems.Popup
>     For i = 0 To ComboBoxItems.Count - 1
>       If LCase(ComboBoxItems[i].Text) Like LCase(textToCursor) & "*" Then
>         ComboBoxItems.Index = i
>         Break
>       Endif
>     Next
>
>   Else If Key.Code = Key.BackSpace Then
>     If ComboBoxItems.Pos = 0 Then
>     Else
>       textPosition = ComboBoxItems.Pos - 1
>       textToCursor = Mid(ComboBoxItems.Text, 1, textPosition)
>       For i = 0 To ComboBoxItems.Count - 1
>         If LCase(ComboBoxItems[i].Text) Like LCase(textToCursor) & "*" Then
>           ComboBoxItems.Text = ComboBoxItems[i].Text
>           ComboBoxItems.Pos = textPosition
>           ComboBoxItems.Select(textPosition, Len(ComboBoxItems.Text) -
> textPosition)
>           Break
>         Endif
>       Next
>     Endif
>
>   Else
>     If ComboBoxItems.Pos = 0 Then
>     Else
>       textPosition = ComboBoxItems.Pos
>       textToCursor = Mid(ComboBoxItems.Text, 1, textPosition)
>       For i = 0 To ComboBoxItems.Count - 1
>         If LCase(ComboBoxItems[i].Text) Like LCase(textToCursor) & "*" Then
>           ComboBoxItems.Text = ComboBoxItems[i].Text
>           ComboBoxItems.Pos = textPosition
>           ComboBoxItems.Select(textPosition, Len(ComboBoxItems.Text) -
> textPosition)
>           Break
>         Endif
>       Next
>     Endif
>
>   Endif
>
> End
>
> Public Sub ComboBoxItems_Click()
>
>   TextBox1.Text = ComboBoxItems.Text
>
> End
>
>
>
> --
> Regards
> Safiur Rahman
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230206/3311a324/attachment.htm>


More information about the User mailing list