0 Replies - 539 Views - Last Post: 04 June 2010 - 04:47 AM Rate Topic: -----

#1 CodeFather  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 07-March 10

Making Textbox Intelligent

Posted 04 June 2010 - 04:47 AM

hey!
how to build intellisense for a text box? at the moment i am using the autocomplete properties of a text box in vb.net
here's a picture :
Posted Image
but once you have typed one word (say that word is not there in the auto complete source) the auto complete help will not show up for the next word (which may belong to the auto complete source list)

so to work around this problem i wrote a small .net program which appends every word typed in the text box to the auto complete source list

here's a picture of the result / what i actually want
Posted Image
and here's the code for doing the above mentioned
Public Class Form1
    Dim original As AutoCompleteStringCollection
    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Asc(e.KeyChar) = 32 Then
            Dim coll As AutoCompleteStringCollection = DirectCast(sender, TextBox).AutoCompleteCustomSource
            For i As Integer = 0 To coll.Count - 1
                coll(i) = DirectCast(sender, TextBox).Text & " " & original(i)
            Next
            DirectCast(sender, TextBox).Text = DirectCast(sender, TextBox).Text & " "
            DirectCast(sender, TextBox).Selectionstart = DirectCast(sender, TextBox).Text.Length
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        original = New AutoCompleteStringCollection()
        For i As Integer = 0 To TextBox1.AutoCompleteCustomSource.Count - 1
            Debug.Print(i)
            original.Add(TextBox1.AutoCompleteCustomSource(i))
        Next
    End Sub
End Class

thanks for your help

Is This A Good Question/Topic? 0
  • +

Page 1 of 1