Click here to Skip to main content
15,913,773 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Combo Box Filter Pin
ccotton33330-Jun-04 10:56
ccotton33330-Jun-04 10:56 
GeneralRe: Combo Box Filter Pin
lildragon30-Jun-04 11:39
lildragon30-Jun-04 11:39 
GeneralRe: Combo Box Filter Pin
Ravi S.V.30-Jun-04 21:36
Ravi S.V.30-Jun-04 21:36 
GeneralRe: Combo Box Filter Pin
Anonymous1-Jul-04 6:55
Anonymous1-Jul-04 6:55 
GeneralRe: Combo Box Filter Pin
Serge Lobko-Lobanovsky1-Jul-04 4:17
Serge Lobko-Lobanovsky1-Jul-04 4:17 
GeneralRe: Combo Box Filter Pin
Anonymous1-Jul-04 7:03
Anonymous1-Jul-04 7:03 
GeneralNew Combo Box Filter Pin
lildragon5-Jul-04 8:09
lildragon5-Jul-04 8:09 
GeneralLatest ComboBox Filter Code Pin
lildragon5-Jul-04 10:42
lildragon5-Jul-04 10:42 
Hi everyone, this code handles backspaces, populates the combobox..filters out the stuff that doesn't match the users input, but I am having a problem when I try to type strings that match a single word, but with more chars. I would like to be able to continue typing and displaying nothing in the combobox type thing. But, when I type the extra chars, the combobox forces me back to the start position of the combobox. Does anyone have any idea what is going on? Thank you.

Imports System.Drawing.Graphics
Imports System.Drawing.Brush
Imports System.Drawing.Drawing2D
Imports System.Drawing

Imports System.ComponentModel.Design.Serialization
Imports System.ComponentModel

Public Class Form1
Inherits System.Windows.Forms.Form
Dim origData_cbo As New ArrayList

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
origData_cbo.Add("Please Select or Type an Item Name")
origData_cbo.Add("acada")
origData_cbo.Add("acura")
origData_cbo.Add("amy")
origData_cbo.Add("apple")
origData_cbo.Add("bananna")
origData_cbo.Add("orange")
origData_cbo.Add("pear")
origData_cbo.Add("person")
origData_cbo.Add("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890")

cbo1.DataSource = origData_cbo
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Uc_measurements2 As SingerProtype.uc_measurements
Friend WithEvents Uc_measurements3 As SingerProtype.uc_measurements
Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker
Friend WithEvents Uc_measurements1 As SingerProtype.uc_measurements
Friend WithEvents cbo1 As System.Windows.Forms.ComboBox
Friend WithEvents Label1 As System.Windows.Forms.Label
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.Uc_measurements2 = New SingerProtype.uc_measurements
Me.Uc_measurements3 = New SingerProtype.uc_measurements
Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker
Me.Uc_measurements1 = New SingerProtype.uc_measurements
Me.cbo1 = New System.Windows.Forms.ComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Uc_measurements2
'
Me.Uc_measurements2.BackColor = System.Drawing.Color.DarkGray
Me.Uc_measurements2.displayActual = False
Me.Uc_measurements2.Location = New System.Drawing.Point(8, 248)
Me.Uc_measurements2.Name = "Uc_measurements2"
Me.Uc_measurements2.Size = New System.Drawing.Size(392, 146)
Me.Uc_measurements2.TabIndex = 1
'
'Uc_measurements3
'
Me.Uc_measurements3.BackColor = System.Drawing.Color.DarkGray
Me.Uc_measurements3.displayActual = False
Me.Uc_measurements3.Location = New System.Drawing.Point(416, 8)
Me.Uc_measurements3.Name = "Uc_measurements3"
Me.Uc_measurements3.Size = New System.Drawing.Size(392, 152)
Me.Uc_measurements3.TabIndex = 2
'
'DateTimePicker1
'
Me.DateTimePicker1.Location = New System.Drawing.Point(440, 240)
Me.DateTimePicker1.Name = "DateTimePicker1"
Me.DateTimePicker1.Size = New System.Drawing.Size(192, 20)
Me.DateTimePicker1.TabIndex = 4
'
'Uc_measurements1
'
Me.Uc_measurements1.BackColor = System.Drawing.Color.DarkGray
Me.Uc_measurements1.displayActual = False
Me.Uc_measurements1.Location = New System.Drawing.Point(16, 8)
Me.Uc_measurements1.Name = "Uc_measurements1"
Me.Uc_measurements1.Size = New System.Drawing.Size(392, 152)
Me.Uc_measurements1.TabIndex = 5
'
'cbo1
'
Me.cbo1.Location = New System.Drawing.Point(408, 336)
Me.cbo1.MaxDropDownItems = 10
Me.cbo1.Name = "cbo1"
Me.cbo1.Size = New System.Drawing.Size(296, 21)
Me.cbo1.TabIndex = 6
Me.cbo1.Text = "Please Select or Type an Item Name"
'
'Label1
'
Me.Label1.BackColor = System.Drawing.Color.Transparent
Me.Label1.Location = New System.Drawing.Point(408, 320)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(304, 16)
Me.Label1.TabIndex = 7
Me.Label1.Text = "AutoFill Combo Box that allows user to type extra if need be"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.ControlDarkDark
Me.ClientSize = New System.Drawing.Size(824, 454)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.cbo1)
Me.Controls.Add(Me.Uc_measurements1)
Me.Controls.Add(Me.DateTimePicker1)
Me.Controls.Add(Me.Uc_measurements3)
Me.Controls.Add(Me.Uc_measurements2)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Dim uc As uc_measurements = New uc_measurements
'Uc_measurements1.showActual(False)
Uc_measurements1.showActual(True)
Uc_measurements2.showActual(False)

'[Paint gradient form]
SetStyle(ControlStyles.AllPaintingInWmPaint Or _
ControlStyles.DoubleBuffer Or _
ControlStyles.ResizeRedraw Or _
ControlStyles.UserPaint, True)
'[/Paint gradient form]

End Sub

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

'[Declare variables]
Dim formGraphics As Graphics = e.Graphics
Dim gradientMode As LinearGradientMode = LinearGradientMode.ForwardDiagonal

Dim gradientBrush As New _
LinearGradientBrush(New Rectangle(0, 0, Me.Width, Me.Height), Color.FromArgb(236, 233, 216), Color.FromArgb(52, 101, 75), gradientMode)
formGraphics.FillRectangle(gradientBrush, ClientRectangle)
'[/Declare variables]

End Sub
'Function used to handle the on key up event
Private Sub cbo1_keyUp(ByVal sender As Object, ByVal e As KeyEventArgs) Handles cbo1.KeyUp
AutoCompleteCombo_keyUp(sender, e)
cbo1.DroppedDown() = True
End Sub

'Function used to display first matching item as user types letters into the combo box
Public Sub AutoCompleteCombo_keyUp(ByVal sender As Object, ByVal e As KeyEventArgs)
Dim cbo As ComboBox = sender 'takes the combo box calling the function and sets it to a local combobox

'Allow select keys without Autocompleting
Select Case e.KeyCode
Case Keys.Left, Keys.Right, Keys.Up, Keys.Delete, Keys.Down, Keys.Back
If e.KeyValue = Keys.Back Then
append(sender, e, "1")
End If
Exit Sub
End Select

append(sender, e, "0")
End Sub

'Append possible text that may follow
Private Sub append(ByVal sender As Object, ByVal e As EventArgs, ByVal minus As Integer)

Dim cbo As ComboBox = sender
Dim foundIndex As Integer = -1 'takes the users typed text and if found in a datasource, stores the index
Dim foundArrLst As New ArrayList
Dim foundText As String = ""
Dim typedText As String = "" 'takes the text typed into the combobox by the users and stores it into a local string variable
Dim appendText As String = ""
Dim posCursor As Integer = cbo.SelectionStart 'takes the position of the cursor when the function is called

If (cbo.Text.Length > 0) Then
typedText = cbo.Text.Substring(0, cbo.Text.Length - minus)
End If

resetComboBox(sender, e)
foundIndex = cbo.FindString(typedText)

If posCursor <> 0 Then
If foundIndex >= 0 Then
'Use the ListControl.GetItemText to resolve the Name in case the Combo was Data bound
'Get the Item from the list (Return Type depends if Datasource was bound or List Created)
foundText = cbo.GetItemText(cbo.Items.Item(foundIndex))

'Append then found text to the typed text to preserve case
appendText = foundText.Substring(typedText.Length)
cbo.Text = typedText + appendText

reduceList(foundIndex, foundArrLst, cbo, typedText)
cbo.SelectionStart = typedText.Length
cbo.SelectionLength = appendText.Length
End If
Else
resetComboBox(sender, e)
End If
End Sub

'Reduce the List of Possibilities
Private Sub reduceList(ByVal foundIndex As Integer, ByRef foundArray As ArrayList, _
ByRef cbo As ComboBox, ByVal typedText As String)
'If we found the Typed Text in the list then Autocomplete
If foundIndex >= 0 Then
Dim i As String
For Each i In cbo.Items
' try a partial string match, looking at the first few letters of each name
If Mid(i, 1, Len(typedText)) = typedText Then
' if there's a match, stick the name in the results list
foundArray.Add(i)
End If
Next
End If

'If we found the Typed Text in the list then Autocomplete
'If foundIndex >= 0 Then
'Dim item As String
'For Each item In cbo.Items
' try a partial string match, looking at the first few letters of each name
' can also use If Mid(i, 1, Len(sTypedText)) = sTypedText Then
' if there's a match, stick the name in the results list
'If Microsoft.VisualBasic.Left(item, typedText.Length).ToUpper = typedText.ToUpper Then
'foundArray.Add(item)
'End If
'Next
'End If
cbo.DataSource = foundArray
adjustWidth_dropDown(cbo)
cbo.DroppedDown = True
End Sub

'Calls a function to adjust the width of the combo box
Private Sub cbo1_DropDown(ByVal sender As Object, ByVal e As EventArgs) Handles cbo1.DropDown
adjustWidth_dropDown(cbo1)
End Sub

'Function called when the focus leaves the combobox to reset the values in the drop down list
Private Sub cbo1_FocusLeavePrivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbo1.Leave
resetComboBox(sender, e)
End Sub

'Function used to reset the values in the combo box drop down list to the original when a user leaves the box
Private Sub resetComboBox(ByVal sender As Object, ByVal e As System.EventArgs)
Dim cbo As ComboBox = sender
Dim prevSelected As String

prevSelected = cbo.Text.ToString()
cbo.DataSource = origData_cbo
If cbo.FindString(prevSelected) >= 0 Then
cbo.SelectedItem = cbo.Items.Item(cbo.FindString(prevSelected))
cbo.Text = prevSelected
End If
End Sub

'Function used to handle longer text strings that don't fit in a sized combo box
Public Sub adjustWidth_dropDown(ByRef cbo As ComboBox)
Dim i As Integer
Dim tempLength As Integer = 0
Dim tempString As String = ""
Dim largestWidth As Integer = 0
Dim newWidth As Integer
Dim g As Graphics = cbo.CreateGraphics()
Dim tempFont As Font = cbo1.Font
Dim vertScrollWidth As Integer = (cbo.Items.Count > cbo.MaxDropDownItems) 'check to see if we need a scroll bar
For i = 0 To cbo.Items.Count - 1
newWidth = g.MeasureString(cbo.Items.Item(i), tempFont).Width + vertScrollWidth
If (largestWidth < newWidth) Then
largestWidth = newWidth
End If
cbo.DropDownWidth = largestWidth
Next
End Sub

Private Sub cbo1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbo1.GotFocus
cbo1.DroppedDown() = True
End Sub

'Not Working
Private Sub AutoCompleteComboBox1_Submit(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbo1.Enter
Dim wComboValue As String = "(New Item)"
If Not IsNothing(cbo1.SelectedValue) Then
wComboValue = cbo1.SelectedValue
End If
'goes in the append text to get rid of wildcards
' Remove *, ' e % from the string
'If Strings.Right(cbo.Text, 1) = "*" Or Strings.Right(cbo.Text, 1) = "'" Or Strings.Right(cbo.Text, 1) = "%" Then
'cbo.Text = cbo.Text.Substring(0, Len(cbo.Text) - 1)
'cbo.SelectionStart = cbo.Text.Length
'Exit Sub
'End If
'If cbo.Text.IndexOf("*") <> -1 Or cbo.Text.IndexOf("'") <> -1 Or cbo.Text.IndexOf("%") <> -1 Then
'cbo.Text = cbo.Text.Replace("*", "").Replace("'", "").Replace("%", "")
'End If
End Sub
End Class
GeneralInserting Image into Richtext Box Control Pin
Harish Bailwad30-Jun-04 1:41
Harish Bailwad30-Jun-04 1:41 
GeneralRe: Inserting Image into Richtext Box Control Pin
Dave Kreskowiak30-Jun-04 12:06
mveDave Kreskowiak30-Jun-04 12:06 
GeneralInserting Image into Richtext Box Control Pin
hari_vb30-Jun-04 1:41
susshari_vb30-Jun-04 1:41 
GeneralDrag URL -&gt; Drop File Pin
Timotei_Younge29-Jun-04 23:16
Timotei_Younge29-Jun-04 23:16 
GeneralRe: Drag URL -&gt; Drop File Pin
Dave Kreskowiak30-Jun-04 2:42
mveDave Kreskowiak30-Jun-04 2:42 
Questionhow to put an exe file into vb6.0 Pin
saimram29-Jun-04 19:36
saimram29-Jun-04 19:36 
AnswerRe: how to put an exe file into vb6.0 Pin
Dave Kreskowiak30-Jun-04 2:39
mveDave Kreskowiak30-Jun-04 2:39 
Generaldata type error Pin
GaryKoh29-Jun-04 16:50
GaryKoh29-Jun-04 16:50 
GeneralRe: data type error Pin
Dave Kreskowiak30-Jun-04 0:38
mveDave Kreskowiak30-Jun-04 0:38 
GeneralRe: data type error Pin
GaryKoh30-Jun-04 1:24
GaryKoh30-Jun-04 1:24 
GeneralRe: data type error Pin
Dave Kreskowiak30-Jun-04 12:04
mveDave Kreskowiak30-Jun-04 12:04 
GeneralRe: data type error Pin
GaryKoh30-Jun-04 17:13
GaryKoh30-Jun-04 17:13 
GeneralRe: data type error Pin
Dave Kreskowiak1-Jul-04 1:21
mveDave Kreskowiak1-Jul-04 1:21 
GeneralRe: data type error Pin
GaryKoh1-Jul-04 3:29
GaryKoh1-Jul-04 3:29 
GeneralDon't know where to put this. ACCESS! PLEASE HELP Pin
Rip V. Winkle29-Jun-04 15:34
Rip V. Winkle29-Jun-04 15:34 
GeneralRe: Don't know where to put this. ACCESS! PLEASE HELP Pin
KevinMac29-Jun-04 18:27
KevinMac29-Jun-04 18:27 
GeneralRe: Don't know where to put this. ACCESS! PLEASE HELP Pin
Rip V. Winkle11-Jul-04 8:25
Rip V. Winkle11-Jul-04 8:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.