Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

AutoComplete combobox

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-09-2008, 07:29 AM
Basic4ppc Veteran
 
Join Date: Sep 2008
Location: Brisbane, Australia
Posts: 317
Default AutoComplete combobox

Hi all.

I am now going to put my auto complete combobox into a library.

So far it's looking good.

It doesn't need to use timers - I'm writing it in vb.net and the guts of the processing is in the KeyUp event of the textbox of the library.

I'll post it up when I'm done which will be shortly.

regards, Ricky
Reply With Quote
  #2 (permalink)  
Old 10-09-2008, 08:17 AM
Basic4ppc Veteran
 
Join Date: Sep 2008
Location: Brisbane, Australia
Posts: 317
Default umm a slight challenge

I have created the autocomplete functionality just fine.

Now I need to be able to add the control to a tab page from the tabcontrol.

I'm not sure how to do this.

At present I can add it to a form easily.

here is the entire vb.net code for the dll

Imports System.Windows.Forms
Imports System.Drawing

Public Class AutoCompleteCombo
Implements IDisposable 'Inherit from IDisposable if you need Basic4ppc to free resources when the application is closed.
Private WithEvents txtText As System.Windows.Forms.TextBox
Private WithEvents cboCombo As System.Windows.Forms.ComboBox
Public Event TextChanged As EventHandler
Public Event SelectionIndexChanged As EventHandler
Public Event GotFocus As EventHandler
Public Event LostFocus As EventHandler
Private eventTextChangedObject() As Object 'One object[] for each event (one event here).
Private eventSelectionIndexChangedObject As Object
Private eventGotFocusObject As Object
Private eventLostFocusObject As Object

Private mAutoCompleteOn As Boolean = True

Sub New(ByVal FormName As Control, ByVal Left As Int32, ByVal Top As Int32, ByVal Width As Int32, ByVal Height As Int32)
cboCombo = New ComboBox
cboCombo.Top = Top
cboCombo.Left = Left
cboCombo.Width = Width
cboCombo.Height = Height

txtText = New TextBox
txtText.Top = Top
txtText.Left = Left
txtText.Width = Width - 15
txtText.Height = Height

FormName.Controls.Add(cboCombo)
FormName.Controls.Add(txtText)
txtText.BringToFront()

mAutoCompleteOn = True

eventTextChangedObject = New Object() {Me, "TextChanged"}
eventSelectionIndexChangedObject = New Object() {Me, "SelectionIndexChanged"}
eventGotFocusObject = New Object() {Me, "GotFocus"}
eventLostFocusObject = New Object() {Me, "LostFocus"}
End Sub

Public Property AutoCompleteOn() As Boolean
Get
Return mAutoCompleteOn
End Get
Set(ByVal value As Boolean)
mAutoCompleteOn = value
End Set
End Property

Private Sub txtText_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtText.GotFocus
RaiseEvent GotFocus(eventGotFocusObject, Nothing)
End Sub

Private Sub txtText_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtText.KeyUp
Dim strg As String = txtText.Text.ToUpper
Dim item As String
Dim i As Integer
Dim found As Boolean = False
Dim obj As Object

If e.KeyData = Keys.Back Then
e.Handled = True
Exit Sub
End If

If mAutoCompleteOn = False Then
e.Handled = True
Exit Sub
End If

For i = 0 To cboCombo.Items.Count - 1
obj = cboCombo.Items.Item(i)
'If TypeOf obj Is Data.DataRowView Then
'Dim drv As Data.DataRowView = obj
'get the field from the displaymember
'Dim dsp As String = DisplayMember
'Dim tmp As Integer = dsp.IndexOf(".") + 1
'If tmp > 0 Then
'item = dsp.Substring(tmp)
'item = drv.Row.Item(item)
'Else
'item = drv.Row.Item(dsp)
'End If
'ElseIf TypeOf obj Is String Then
item = obj
'End If
'item = item.ToUpper()
If item.ToUpper.StartsWith(strg) Then
found = True
Exit For
End If
Next

If found Then
txtText.Text = item
txtText.SelectionStart = strg.Length
txtText.SelectionLength = txtText.Text.Length - strg.Length
cboCombo.SelectedIndex = i
Else
'RaiseEvent NotInList(txtText.Text)
Me.Height = txtText.Height
End If
End Sub

Private Sub txtText_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtText.LostFocus
RaiseEvent LostFocus(eventLostFocusObject, Nothing)
End Sub


Private Sub txtText_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtText.TextChanged
RaiseEvent TextChanged(eventTextChangedObject, Nothing)
End Sub

Public Property Text() As String
Get
Return txtText.Text
End Get
Set(ByVal value As String)
txtText.Text = value
End Set
End Property

Public Property Height() As Int32
Get
Return cboCombo.Height
End Get
Set(ByVal Value As Int32)
cboCombo.Height = Value
txtText.Height = Value
End Set
End Property

Public Property Width() As Int32
Get
Return cboCombo.Width
End Get
Set(ByVal value As Int32)
cboCombo.Width = value
txtText.Width = value - 15
End Set
End Property

Public Sub Add(ByVal strToAdd As String)
cboCombo.Items.Add(strToAdd)
End Sub

Public Sub Dispose() Implements System.IDisposable.Dispose
If Not txtText Is Nothing Then
txtText.Dispose()
End If

If Not cboCombo Is Nothing Then
cboCombo.Dispose()
End If
End Sub

Private Sub cboCombo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCombo.SelectedIndexChanged
txtText.Text = cboCombo.Items(cboCombo.SelectedIndex)
RaiseEvent SelectionIndexChanged(eventSelectionIndexChangedOb ject, Nothing)
End Sub
End Class


any ideas?

regards, Ricky
Reply With Quote
  #3 (permalink)  
Old 10-09-2008, 08:47 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Now I need to be able to add the control to a tab page from the tabcontrol.

I'm not sure how to do this.
Add it to a form then use :-

TabControl.AddControl(comboname.ControlRef, page, left, top)

For this to work you need a property to return a reference to your underlying control. It is good practice to always provide this reference as it can also be used with things like AddEvent and the Door library. You probably don't need the Set but I normally include it.
Code:
Public Property ControlRef() As Control
  Get
    
Return cboCombo 
  
End Get
  Set(ByVal value 
As Control)
    cboCombo = value
  
End Set
End Property
Reply With Quote
  #4 (permalink)  
Old 10-09-2008, 09:14 AM
Basic4ppc Veteran
 
Join Date: Sep 2008
Location: Brisbane, Australia
Posts: 317
Default slight problem with it

thanks agraham but now the autoselect part of the combox doesn't work.

Do I also need to expose the textbox of the dll like I do the combobox?

regards, Ricky

EDIT: I did and it now works. Thanks a lot mate
I had to add a Method that brings the textbox to the front

Last edited by Ricky D : 10-09-2008 at 09:44 AM.
Reply With Quote
  #5 (permalink)  
Old 11-17-2008, 09:57 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 2,344
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

Ricky, I've been trying to make sense of you code in the dll, as you posted, and I'm not able to...
I've learned how to make dlls in c#, and although the two are not that diferent, some syntax just gets me off...
Could you release your dll in the Aditional libraries?
I'm sure that, others like me, would benefit from it...

Thanks in advance
__________________
Paulo Gomes - Porto, Portugal - Living/Working in France
Mobile Device: Samsung Galaxy S, Android 2.3.4 CUstom ROM
Laptop: Toshiba NB100-130 (running on Win7Ultimate)

My Posts helped you? Consider Buying me a Porto Glass!
Reply With Quote
  #6 (permalink)  
Old 11-18-2008, 07:08 PM
Basic4ppc Veteran
 
Join Date: Sep 2008
Location: Brisbane, Australia
Posts: 317
Default ok, when i get home

no worries mate.

i'll post the C# version plus the .dll

i need to put together a .chm help file.

i haven't implemented the items collection.

it supports vga & qvga.

regards, Ricky
Reply With Quote
  #7 (permalink)  
Old 11-18-2008, 07:09 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 2,344
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

Thanks...Please PM after release to add you to the dll version listing...
__________________
Paulo Gomes - Porto, Portugal - Living/Working in France
Mobile Device: Samsung Galaxy S, Android 2.3.4 CUstom ROM
Laptop: Toshiba NB100-130 (running on Win7Ultimate)

My Posts helped you? Consider Buying me a Porto Glass!
Reply With Quote
  #8 (permalink)  
Old 11-19-2008, 07:45 AM
Basic4ppc Veteran
 
Join Date: Sep 2008
Location: Brisbane, Australia
Posts: 317
Default I'll put it on hold

so I can rewrite it so it can do a ShowDropdown method.

This requires me to ditch the combobox in the dll and put in place a button and a listbox.

As this is in C# and I'm still learning it might take me a couple of weeks.

I haven't used a listbox in C# yet.

regards, Ricky
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
ComboBox Value RandomCoder Basic4ppc Wishlist 7 11-18-2011 11:08 AM
Case and AutoComplete control names agraham Beta Versions 1 09-18-2008 05:06 PM
Autocomplete combo box??? Ricky D Questions (Windows Mobile) 9 09-11-2008 06:03 AM
ComboBox ceaser Questions (Windows Mobile) 2 08-25-2008 03:52 PM
ComboBox Raytracer Italian Forum 3 04-15-2008 04:15 PM


All times are GMT. The time now is 02:41 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0