Clear Combobox Items

From: stingrays (stingrays_at_mindspring.com)
Date: 04/29/04


Date: 29 Apr 2004 08:21:53 -0700

Below is my code for a combobox. Basically, I have 2 comboboxes. 1
box is the application selection and the other retrieves data from the
dataset (SQL Server) to populate the drop down in the otehr box. I
want to make a selection in the app combobox, update the second box
and when I select a new app, it should remove all items in teh 2nd
combobox and refresh the list with only the selected app. With this
code it appears the binding is not occurring properly after I detach
it. I have tried Remove, RemoveAt and Items.Clear() and nothing seems
to work. Currently, I receive the message in my 2nd combo box that
says, "System.Data.DataViewManagerListItemTypeDescriptor".

Please help me! It can't be this difficult to drop a datasource,
clear items, bind the datasource and fill the dataadapter.

Thanks in advance.

Private Sub cboApp_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cboApp.SelectedIndexChanged

        Dim selectSQL As String = "SELECT App, Name, Destination FROM
KickOffFTP WHERE (App = @app_param) order by Name"
        Dim selectCMD As SqlCommand = New SqlCommand(selectSQL,
SqlConnection1)
        remove()
        Try
            
            daFTPProcess.SelectCommand = selectCMD

            selectCMD.Parameters.Add("@app_param", cboApp.Text)
            'MsgBox(cboApp.Text)

            'Fill, Reset and Fill dataset
            'daFTPProcess = New SqlDataAdapter(selectSQL,
SqlConnection1)
            'BindMyCombox()

            'cboFTPProcess.DataSource = Nothing
            'cboFTPProcess.DisplayMember = Nothing
            'cboFTPProcess.Items.Clear()

            'cboFTPProcess.DataSource = DsFTPProcess1
            'cboFTPProcess.DisplayMember = "KickOffFTP.Name"
            'daFTPProcess.SelectCommand = selectCMD
            daFTPProcess.Fill(DsFTPProcess1)

        Catch exc As Exception
            ' Display an error message.
            MsgBox(exc.Message)
        End Try

    End Sub

    Sub remove()

        'MsgBox(cboFTPProcess.Items.Count)
        Try
            myIndex = cboFTPProcess.Items.Count
            If myIndex > -1 Then
                cboFTPProcess.DataSource = Nothing
                Do While myIndex > 0 'Zero based
                    cboFTPProcess.Items.RemoveAt(0) 'Or...
                    'myCombo.Items.RemoveAt(myIndex) 'Beta 2 shows the
above line.
                    'Remove in reverse order, maybe items may move as
one is removed????
                    myIndex = myIndex - 1
                Loop
                cboFTPProcess.DataSource = DsFTPProcess1
            End If
        Catch exc As Exception
            ' Display an error message.
            MsgBox(exc.Message)
        End Try

    End Sub



Relevant Pages

  • RE: Data table function - A dropdown list replacement for VLookup.
    ... To do this you would be well served by a UserForm which we will create now. ... This will create a ComboBox control on the form. ... “Typing in the selection box will bring matching choices, ... The above code that we just pasted into the code window will take the data ...
    (microsoft.public.excel.worksheet.functions)
  • RE: Data table function - A dropdown list replacement for VLookup.
    ... To do this you would be well served by a UserForm which we will create now. ... This will create a ComboBox control on the form. ... “Typing in the selection box will bring matching choices, ... Private Sub Clear_Form_Click ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Calculating off combobox selections
    ... selection from the dropdown combobox list in field A. That's it! ... 'number') in field 'B' based on the selection from the dropdown combobox. ... There is no 'combo box' form field in Word 2003, ...
    (microsoft.public.word.docmanagement)
  • Re: How to with a combo box (to Rick and Steve)
    ... the value from column B (column order B, C and D) and the second from ... Assuming that your first visible column is also your bound column (not clear ... then you use the AfterUpdate code of each ComboBox ... make the selection manually). ...
    (comp.databases.ms-access)
  • Re: Separating text by carriage return
    ... Contro wrote: ... I don't know why you refuse combobox. ... use to restrict selection to list items only. ... So I am wanting a shortcut to show a sentence for getting a grade A. ...
    (microsoft.public.vb.database)