Connecting Tech Pros Worldwide Forums | Help | Site Map

Clear Combobox Items

stingrays
Guest
 
Posts: n/a
#1: Jul 21 '05
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

Closed Thread


Similar .NET Framework bytes