Autocomplete combo box???

Ricky D

Well-Known Member
Licensed User
:sign0085:

Hi people,

I have written an app on my winmobile 6 ppc in VB.NET but am having what I think are memory leak problems and possibly problems with it's garbage disposal methods.

What I'd like to do is write my app in Basic4ppc but I need to have the functionality of an autocomplete combobox. I've created one in vb.net and would like to know if anyone has managed to implement something like this in Basic4ppc?

regards,

Ricky
 

Ricky D

Well-Known Member
Licensed User
Thanks but doesn't really help

Thanks Cableguy but this isn't what I need.

I need to be able to write it in Basic4ppc.

I have tried to do this with a TextBox and a ListBox.
The TextBox is where the user types.
The ListBox contains items that will be searched.

a Textbox in basic4ppc only has GotFocus, KeyPress and LostFocus events.

The one I created in VB.NET for mobile uses a combo box and textbox and the critical code is in the KeyUp event of the textbox - Basic4ppc doesn't have this event.

or are you suggesting I compile the code in the article you suggested and create it as a dll? If so I'm not sure how to do that and make it work in Basic4ppc.

I'm not sure what you are saying. :sign0013:
 

Cableguy

Expert
Licensed User
The code in the artical I referd you to, can easely be converted to a DLL and be used from b4p.
 

BjornF

Active Member
Licensed User
I think this works, after a fashion - there might be a better way of doing it...;)


B4X:
Sub Globals
   'Declare the global variables here.
End Sub

Sub App_Start
   frm1.Show

   lstbox1.Add("and let us start")  
   lstbox1.Add("first")
   lstbox1.Add("firstly")
   lstbox1.Add("firstlyfinal")
   lstbox1.Add("last")
End Sub


Sub TxtBox1_KeyPress (key)
   timer1.Enabled=True     'essentially works like a key-up, choose a good interval
End Sub


Sub Timer1_Tick
   timer1.Enabled=false
   
   txt=txtbox1.Text
   For i=0 To lstbox1.Count-1
      If StrIndexOf(lstbox1.Item(i),txt,0)=0 Then
         txtbox1.Text=lstbox1.Item(i)
         txtbox1.SelectionStart=StrLength(txt)
         txtbox1.SelectionLength=StrLength(lstbox1.Item(i))
         Exit
      End If
   Next
End Sub
(doesn't work with backspace/delete at present though)

all the best / Björn
 
Last edited:

Mr_Gee

Active Member
Licensed User
I think this works, after a fashion - there might be a better way of doing it...;)


B4X:
...
(doesn't work with backspace/delete at present though)

all the best / Björn
Thats works pretty well actually... good job :)
 

Ricky D

Well-Known Member
Licensed User
the interval?

Looks good. What is the timer interval?

regards, Ricky
 

Ricky D

Well-Known Member
Licensed User
Interval

I set the interval at 50ms. Works fine.

Now to figure out the backspace and delete issue....

thanks guys

Ricky
 

BjornF

Active Member
Licensed User
New improved version :)
Now with support for backspace,
delete also seems to work after a fashion

B4X:
Sub Globals
   'Declare the global variables here.
   Dim Backspace
End Sub

Sub App_Start
   frm1.Show
   lstbox1.Add("and let us start")
   lstbox1.Add("first")
   lstbox1.Add("firstly")
   lstbox1.Add("firstlyfinal")
   lstbox1.Add("last")
End Sub


Sub TxtBox1_KeyPress (key)
   If key=Chr(8) Then
      Backspace=True
   Else
      Backspace=False
   End If
   timer1.Enabled=True
End Sub

Sub Timer1_Tick
   timer1.Enabled=false
   
   txt=txtbox1.Text
   If Backspace AND StrLength(txt)>0 Then
      txt=SubString(txt,0,StrLength(txt)-1)
   End If
   
   For i=0 To lstbox1.Count-1
      If StrIndexOf(lstbox1.Item(i),txt,0)=0 Then
         txtbox1.Text=lstbox1.Item(i)
         txtbox1.SelectionStart=StrLength(txt)
         txtbox1.SelectionLength=StrLength(lstbox1.Item(i))
         Exit
      End If
   Next
End Sub
all the best / Björn
 
Last edited:

Ricky D

Well-Known Member
Licensed User
Thanks

That works great.

I have found the Del key doesn't fire the KeyPressed event.

It doesn't worry me much.

regards, Ricky

P.S I've changed my code to use a combobox and have the textbox cover the text part of the combobox, still showing the dropdown arrow.
On the combobox's SelectionChanged event I set the textbox's text to the item selected.
 
Top