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(eventSelectionIndexChangedObject, Nothing)
End Sub
End Class
any ideas?
regards, Ricky