EDN Admin
Well-known member
Sir
I have a two list box and a text box. Listbox 1 contains collective of items, Listbox 2 empty . If I entered something in Textbox, then listbox2 will show . In Which first part of list box contains,Starts with items , Next part contains i endswith items, and last part contains anywhere, I Use this code as follows :Imports Microsoft.VisualBasic
Public Class Form1
Public Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(13) And TextBox1.TextLength <> 0 Then
MsgBox(TextBox1.Text)
End If
If e.KeyChar = Chr(13) And TextBox1.TextLength = 0 Then
ListBox1.Focus()
ListBox1.SelectedIndex = 0
End If
End Sub
Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
If e.KeyCode = Keys.Up And TextBox1.TextLength = 0 Then
ListBox1.Focus()
ListBox1.SelectedIndex = 0
End If
If e.KeyCode = Keys.Up And ListBox2.Items.Count <> 0 Then
ListBox2.Focus()
ListBox2.SelectedIndex = 0
End If
If e.KeyCode = Keys.Down And TextBox1.TextLength = 0 Then
ListBox1.Focus()
ListBox1.SelectedIndex = (ListBox1.Items.Count - 1)
End If
If e.KeyCode = Keys.Down And ListBox2.Items.Count <> 0 Then
ListBox2.Focus()
ListBox2.SelectedIndex = (ListBox2.Items.Count - 1)
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
ListBox2.Show()
ListBox2.Items.Clear()
If TextBox1.Text.Length > 0 Then
ListBox1.Hide()
For index As Integer = 0 To ListBox1.Items.Count - 1
Dim txt = ListBox1.Items(index).ToString()
If txt.StartsWith(TextBox1.Text, StringComparison.CurrentCultureIgnoreCase) Then
ListBox2.Items.Add(txt)
End If
Next
ListBox2.Items.Add("----------------------")
For index As Integer = 0 To ListBox1.Items.Count - 1
Dim txt = ListBox1.Items(index).ToString()
If txt.EndsWith(TextBox1.Text, StringComparison.CurrentCultureIgnoreCase) Then
ListBox2.Items.Add(txt)
End If
Next
ListBox2.Items.Add("----------------------")
For index As Integer = 0 To ListBox1.Items.Count - 1
Dim txt = ListBox1.Items(index).ToString()
If txt.Contains(TextBox1.Text) Then , StringComparison.CurrentCultureIgnoreCase) Then
ListBox2.Items.Add(txt)
End If
Next
End If
If ListBox2.Items.Count <= 0 Then
If TextBox1.TextLength <= 1 Then
ListBox2.Hide()
ListBox1.Show()
MsgBox("please check, item not found22222....")
TextBox1.Clear()
TextBox1.SelectionStart = 0
Else
MsgBox("please check, item not found1111111....")
TextBox1.Text = Microsoft.VisualBasic.Left(TextBox1.Text, (TextBox1.TextLength - 1))
TextBox1.SelectionStart = TextBox1.TextLength
End If
End If
End Sub
Private Sub ListBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ListBox2.KeyPress
If e.KeyChar = Chr(13) Then
TextBox1.Text = ListBox2.SelectedItem
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.TextLength
ListBox2.Hide()
Else
TextBox1.Text = TextBox1.Text + e.KeyChar
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.TextLength
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox2.Hide()
End Sub
Private Sub ListBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ListBox1.KeyPress
If e.KeyChar = Chr(13) Then
TextBox1.Text = ListBox1.SelectedItem
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.TextLength
ListBox1.Hide()
Else
TextBox1.Text = TextBox1.Text + e.KeyChar
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.TextLength
End If
End Sub
End Class
View the full article
I have a two list box and a text box. Listbox 1 contains collective of items, Listbox 2 empty . If I entered something in Textbox, then listbox2 will show . In Which first part of list box contains,Starts with items , Next part contains i endswith items, and last part contains anywhere, I Use this code as follows :Imports Microsoft.VisualBasic
Public Class Form1
Public Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(13) And TextBox1.TextLength <> 0 Then
MsgBox(TextBox1.Text)
End If
If e.KeyChar = Chr(13) And TextBox1.TextLength = 0 Then
ListBox1.Focus()
ListBox1.SelectedIndex = 0
End If
End Sub
Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
If e.KeyCode = Keys.Up And TextBox1.TextLength = 0 Then
ListBox1.Focus()
ListBox1.SelectedIndex = 0
End If
If e.KeyCode = Keys.Up And ListBox2.Items.Count <> 0 Then
ListBox2.Focus()
ListBox2.SelectedIndex = 0
End If
If e.KeyCode = Keys.Down And TextBox1.TextLength = 0 Then
ListBox1.Focus()
ListBox1.SelectedIndex = (ListBox1.Items.Count - 1)
End If
If e.KeyCode = Keys.Down And ListBox2.Items.Count <> 0 Then
ListBox2.Focus()
ListBox2.SelectedIndex = (ListBox2.Items.Count - 1)
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
ListBox2.Show()
ListBox2.Items.Clear()
If TextBox1.Text.Length > 0 Then
ListBox1.Hide()
For index As Integer = 0 To ListBox1.Items.Count - 1
Dim txt = ListBox1.Items(index).ToString()
If txt.StartsWith(TextBox1.Text, StringComparison.CurrentCultureIgnoreCase) Then
ListBox2.Items.Add(txt)
End If
Next
ListBox2.Items.Add("----------------------")
For index As Integer = 0 To ListBox1.Items.Count - 1
Dim txt = ListBox1.Items(index).ToString()
If txt.EndsWith(TextBox1.Text, StringComparison.CurrentCultureIgnoreCase) Then
ListBox2.Items.Add(txt)
End If
Next
ListBox2.Items.Add("----------------------")
For index As Integer = 0 To ListBox1.Items.Count - 1
Dim txt = ListBox1.Items(index).ToString()
If txt.Contains(TextBox1.Text) Then , StringComparison.CurrentCultureIgnoreCase) Then
ListBox2.Items.Add(txt)
End If
Next
End If
If ListBox2.Items.Count <= 0 Then
If TextBox1.TextLength <= 1 Then
ListBox2.Hide()
ListBox1.Show()
MsgBox("please check, item not found22222....")
TextBox1.Clear()
TextBox1.SelectionStart = 0
Else
MsgBox("please check, item not found1111111....")
TextBox1.Text = Microsoft.VisualBasic.Left(TextBox1.Text, (TextBox1.TextLength - 1))
TextBox1.SelectionStart = TextBox1.TextLength
End If
End If
End Sub
Private Sub ListBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ListBox2.KeyPress
If e.KeyChar = Chr(13) Then
TextBox1.Text = ListBox2.SelectedItem
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.TextLength
ListBox2.Hide()
Else
TextBox1.Text = TextBox1.Text + e.KeyChar
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.TextLength
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox2.Hide()
End Sub
Private Sub ListBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ListBox1.KeyPress
If e.KeyChar = Chr(13) Then
TextBox1.Text = ListBox1.SelectedItem
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.TextLength
ListBox1.Hide()
Else
TextBox1.Text = TextBox1.Text + e.KeyChar
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.TextLength
End If
End Sub
End Class
View the full article