Sunday, January 27, 2013

Auto complete imi way for textbox and windows forms

VB. NET WEB FORM Autocomplete textbox with dataset - from ado .net dataset designer






A basic dataset in VB.NET with the get method.

I will use this method to return all the data from the list. I have no idea as to how much calls i am going to be placing on this dataset, it will be wise to call this at "Form Load" and save the list on the client in some kind of generic list, etc.

' A global vairable to hold the list
 Dim col As New AutoCompleteStringCollection

' populate only on the form load to ensure one call is made to the database
Private Sub OwnersPartiesFrm_Load(sender As System.Object, e As System.EventArgs) Handles          'Load List of Known Names
        Dim KnownnNamesDF As New KnownNamesDSTableAdapters.ListofNameTableAdapter
        Dim KnownNamesDT As New KnownNamesDS.ListofNameDataTable
        KnownNamesDT = KnownnNamesDF.GetData()

        For i = 0 To KnownNamesDT.Rows.Count - 1
            col.Add(KnownNamesDT(i).KnownNames.ToString)
        Next
      

    End Sub



'Use the variable to populate on the textbox enter event ( better performance over the text changed event)
 Private Sub TextBoxName_Enter(sender As System.Object, e As System.EventArgs) Handles TextBoxName.Enter
        TextBoxName.AutoCompleteMode = AutoCompleteMode.Suggest
        TextBoxName.AutoCompleteSource = AutoCompleteSource.CustomSource
        TextBoxName.AutoCompleteCustomSource = col

    End Sub

No comments:

Post a Comment