Introduction

 
This code example does demonstrate how to perform a autocompletamennto TextBox control by loading the property of the TextBox AutoCompleteCustomSource from a database table dati.Verrà first creates a local database. sdf SqlCompact where there will be a table called words, then run the Configuration Wizard to create a dataset at the end drag on the form and we will FrmAutoComplete the DataGridView so all the commands available through the BindingNavigator to run the insert update and delete data in the form we will have more than DataBase.Sul DataGridView generated using the DataSet wizard, a button and a box also contains a variable testo.Lesempio tipoSystem.Windows.Form.AutoCompleteCustomSource in the settings of the example.

Building the Sample

To run the sample and the target PC must have the most net.Framework4 SQLCompact 3.5 or higher

Description

  Execution of the application are checked on AutoComplete variable as shown in next code, if nothing of it is created an instance, otherwise it is assigned to the property of the TextBox AutoCompleteSource its value. Using the Upload button and perform an iteration that will be possible to update and save all data entered to the variable AutoComplete.

Forms are available on all components to perform the insert, update, and delete the database table Parole.sdf.

 

Visual Basic
Modifica script|{#scriptcode_dlg.remove_script}
'Classe FrmAutoComplete 
Public Class FrmAutoComplete 
    'Evento Click del Pulsante TABELLAPAROLEBindingNavigatorSaveItem 
    Private Sub TABELLAPAROLEBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgsHandles TABELLAPAROLEBindingNavigatorSaveItem.Click 
        'Verifica il valore del controllo che non è più attivo 
        Me.Validate() 
 
        'Appplica le modifiche all'origine dati sottostante 
        Me.TABELLAPAROLEBindingSource.EndEdit() 
 
        'Aggiorna tutte le modifiche al dataset 
        Me.TableAdapterManager.UpdateAll(Me.ParoleDataSet) 
    End Sub 
 
    'Evento load del form FrmAutoComplete 
    Private Sub FrmAutoComplete_Load(sender As System.Object, e As System.EventArgsHandles MyBase.Load 
        Me.TABELLAPAROLETableAdapter.Fill(Me.ParoleDataSet.TABELLAPAROLE) 
 
        'Assegno alla proprietà AutoCompleteMode della TxtBox il valore AutoCompleteMode.Suggest, necessario 
        'per eseguire l'autocompletamento e suggerire le parole con una specifica lettera iniziale 
        Me.TxtAutoComplete.AutoCompleteMode = AutoCompleteMode.Suggest 
 
        'Assegno alla proprietà AutoCompleteSource il valore AutoCompleteSource.CustomSource per indicare che 
        'la sorgente per l'autocompletemento e prsonalizzata. 
        Me.TxtAutoComplete.AutoCompleteSource = AutoCompleteSource.CustomSource 
 
        ' Se la variabile AutoComplete non e nothing 
        If My.MySettings.Default.AutoComplete IsNot Nothing Then 
 
            'Assegna alla proprietà AutoCompleteCustomSource di TxtAutoCmplete il contenuto della  
            'Variabile AutoComplete 
            Me.TxtAutoComplete.AutoCompleteCustomSource = My.MySettings.Default.AutoComplete 
 
            'Altrimenti 
        Else 
 
            'Crea un istanza di AutoComplete 
            My.MySettings.Default.AutoComplete = New System.Windows.Forms.AutoCompleteStringCollection 
        End If 
    End Sub 
 
    'Evento Click del Pulsante btnAutocomplete 
    Private Sub btnAutocomplete_Click(sender As System.Object, e As System.EventArgsHandles btnAutocomplete.Click 
        'Prova 
        Try 
            'Ottiene il numero di righe che contiene la Tabella del DataGridView 
            Dim rows As Integer = AutoCompleteDataGridView.RowCount 
 
            'Dichiaro una variabile di tipo integer che servirà per scorrere tutte le righe del DataGridWiev  
            Dim i As Integer 
 
            'Eseguo l'iterazione della variabile i 
            For i = 0 To rows - 1 
                'Aggiungo alla variabile AutoComplete tutti i valore dela cella PAROLE  
                My.MySettings.Default.AutoComplete.Add(AutoCompleteDataGridView.Rows(i).Cells("PAROLE").Value.ToString) 
                'Iterazione successiva 
            Next 
 
            'Assegna alla proprietà AutoCompleteCustomSource di TxtAutoCmplete il contenuto della  
            'Variabile AutoComplete 
            Me.TxtAutoComplete.AutoCompleteCustomSource = My.MySettings.Default.AutoComplete 
 
            'Eseguo il salvataggio delle impostazioni dell'applicazione 
            My.MySettings.Default.Save() 
 
        Catch ex As Exception 
 
        End Try 
    End Sub 
End Class 
 

More Information

For more information contact http://community.visual-basic.it/carmelolamonica/