[RESOLVED] Clear Combo Box before Load
Hi,
I am having a function which populates a combobox (cmbProjtype) as shown below,
I am trying to clear cmbProjtype before I populate again to remove duplicates whenever the function is called, but the line of code added (highlighted) is not doing it.. Any help pls
Code:
Private Sub populatecmbprojtype()
Dim cmd As New SqlCommand
Dim conn As SqlConnection = GetDbConnection()
cmbProjtype.SelectedIndex = -1
Try
Dim Projtype As New System.Data.SqlClient.SqlCommand(("Select ProjectType From dbo.tblProjectTypes"), conn)
Using reader As System.Data.SqlClient.SqlDataReader = Projtype.ExecuteReader()
While reader.Read()
Dim ProjectType As String = FixNull(reader.GetValue(0))
cmbProjtype.Items.Add(ProjectType)
End While
End Using
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "VeriSIS")
End Try
End Sub
Thanks
Re: Clear Combo Box before Load
Code:
cmbProjtype.Items.Clear
Re: Clear Combo Box before Load
Instead of this:
Code:
While reader.Read()
Dim ProjectType As String = FixNull(reader.GetValue(0))
cmbProjtype.Items.Add(ProjectType)
End While
do this:
Code:
Dim table As New DataTable
table.Load(reader)
cmbProjtype.DataSource = table
You would set the ComboBox's DisplayMember to "ProjectType" in the designer.
Re: Clear Combo Box before Load