Results 1 to 4 of 4

Thread: [RESOLVED] Auto SuggestAppend issue for ComboBox

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Resolved [RESOLVED] Auto SuggestAppend issue for ComboBox

    Hi all,

    I have a ComboBox on my form and I am trying to create a SuggestAppend for AutoComplete as the end user types. However, I am getting an ArgumentOutOfRangeException when I press the first letter. Then System.Data.DataRowView automatically populates the ComboBox.

    This is what I am doing:
    modDBStuff
    vb Code:
    1. Public Sub AutoSuggestDropDownListFromDB(ByVal cboName As Elegant.Ui.ComboBox, ByVal TableName As String, ByVal ColumnName As String)
    2.         'TODO
    3.         Using SetDatabaseConnection As New SqlConnection(GetDatabaseConnectionString)
    4.             'Specify an SQL query.
    5.             Dim sSQL As String = "SELECT " & ColumnName & " FROM " & TableName
    6.  
    7.             'Assign the SQL query and database connection to the DataAdapter.
    8.             Dim MyDataAdapter As New SqlDataAdapter(sSQL, SetDatabaseConnection)
    9.             'Create a new instance of a DataSet.
    10.             Dim MyDataSet As New DataSet
    11.  
    12.             MyDataSet.Locale = System.Globalization.CultureInfo.CurrentCulture
    13.  
    14.             Try
    15.                 'Clear the DataSet of any previously obtained database information.
    16.                 MyDataSet.Clear()
    17.                 'Refill the DataAdapter with new information obtained from the database.
    18.                 MyDataAdapter.Fill(MyDataSet, TableName)
    19.  
    20.                 'Fill the ComboBox.
    21.                 With cboName
    22.                     'Assign the database table to the DataSource property.
    23.                     .DataSource = MyDataSet.Tables(TableName)
    24.                     'Assign the database column name to the DisplayMember and ValueMember properties.
    25.                     '.DisplayMember = ColumnName
    26.                     '.ValueMember = ColumnName
    27.                     .AutoCompleteMode = AutoCompleteMode.SuggestAppend
    28.                     .AutoCompleteSource = AutoCompleteSource.ListItems
    29.                 End With
    30.             Catch ex As SqlException
    31.                 'Show the end user a message if an error is generated.
    32.                 MessageBox.Show("There was an error retrieving data from table name " & TableName & " for the column " & ColumnName & "." & vbNewLine & vbNewLine & _
    33.                                 "We are going to prepopulate the dropdown menu with a default value; therefore, you can disregard the error." & vbNewLine & vbNewLine & _
    34.                                 "We highly suggest that you click on the plus sign next to the dropdown menu to add some options of your own." & vbNewLine & vbNewLine & _
    35.                                 "The reason why you got this error in the first place is:" & vbNewLine & _
    36.                                 "No data items in the database " & TableName & " to pull." & vbNewLine & vbNewLine & _
    37.                                 "The exception error is:" & vbNewLine & _
    38.                                 ex.Message, _
    39.                                 "Database Information Retrieval Issues", _
    40.                                 MessageBoxButtons.OK, _
    41.                                 MessageBoxIcon.Error, _
    42.                                 MessageBoxDefaultButton.Button1, _
    43.                                 MessageBoxOptions.DefaultDesktopOnly, False)
    44.             Catch ex As ArgumentOutOfRangeException
    45.                 MessageBox.Show(ex.Message, _
    46.                                 "Argument Out Of Range Exception", _
    47.                                 MessageBoxButtons.OK, _
    48.                                 MessageBoxIcon.Error, _
    49.                                 MessageBoxDefaultButton.Button1, _
    50.                                 MessageBoxOptions.DefaultDesktopOnly, False)
    51.             End Try
    52.         End Using 'SetDatabaseConnection.
    53.     End Sub

    _TextChanged
    vb Code:
    1. Private Sub cboClientName_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboClientName.TextChanged
    2.         'Change the content of the input to have the first character capitalized by default.
    3.         'TitleCaseComboBox(cboClientName)
    4.  
    5.         If bNewCallSingle OrElse bNewCallMultiple Then
    6.             'Add some text to the title bar.
    7.             'I didn't add the company name because it shows in the title bar as:
    8.             'ProductName - [Work Log Entry.]
    9.             'ProductName = SupportSpace Call Tracker.
    10.             Me.Text = cboClientName.Text.Trim & "'s Work Log Entry"
    11.         End If
    12.  
    13.         Try
    14.             'Autosuggest clients.
    15.             AutoSuggestDropDownListFromDB(cboClientName, "ClientInformation", "ClientName")
    16.         Catch ex As ArgumentOutOfRangeException
    17.             MessageBox.Show(ex.Message, _
    18.                             "Argument Out Of Range Exception", _
    19.                             MessageBoxButtons.OK, _
    20.                             MessageBoxIcon.Error, _
    21.                             MessageBoxDefaultButton.Button1, _
    22.                             MessageBoxOptions.DefaultDesktopOnly, False)
    23.         End Try
    24.     End Sub

    Any suggestions?
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width