Results 1 to 2 of 2

Thread: How to clear a list box?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Location
    dallas,texasd
    Posts
    26

    How to clear a list box?

    Hello Fellow Coders,

    What code is used to clear a list box, like the one the i am suppling?

    btn_click event---







    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.da1 = New System.Data.SqlClient.SqlDataAdapter
    Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
    Me.cnn = New System.Data.SqlClient.SqlConnection
    '
    'da1
    '
    Me.da1.SelectCommand = Me.SqlSelectCommand1
    Me.da1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Customers", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("LastName", "LastName"), New System.Data.Common.DataColumnMapping("FirstName", "FirstName"), New System.Data.Common.DataColumnMapping("ContactName", "ContactName"), New System.Data.Common.DataColumnMapping("CompanyName", "CompanyName"), New System.Data.Common.DataColumnMapping("CustomerID", "CustomerID"), New System.Data.Common.DataColumnMapping("EmployeeID", "EmployeeID")})})
    '
    'SqlSelectCommand1
    '
    Me.SqlSelectCommand1.CommandText = "SELECT Employees.LastName, Employees.FirstName, Customers.ContactName, Customers." & _
    "CompanyName, Customers.CustomerID, Employees.EmployeeID FROM Customers CROSS JOI" & _
    "N Employees"
    Me.SqlSelectCommand1.Connection = Me.cnn
    '
    'cnn
    '
    Me.cnn.ConnectionString = "workstation id=DESKTOP;packet size=4096;integrated security=SSPI;data source=desk" & _
    "top;persist security info=False;initial catalog=Northwind"

    End Sub
    Protected WithEvents da1 As System.Data.SqlClient.SqlDataAdapter
    Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents cnn As System.Data.SqlClient.SqlConnection
    Protected WithEvents btnEmp As System.Web.UI.WebControls.Button
    Protected WithEvents btnCus As System.Web.UI.WebControls.Button
    Protected WithEvents lstCus As System.Web.UI.WebControls.ListBox
    Protected WithEvents lstemp As System.Web.UI.WebControls.ListBox

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    End Sub

    Private Sub btnEmp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEmp.Click

    Dim ds1 As New DataSet
    da1.Fill(ds1, "Employees")

    Dim dr As DataRow

    For Each dr In ds1.Tables("Employees").Rows
    lstemp.Items.Add(dr.Item("FirstName"))
    Next

    End Sub

    Private Sub btnCus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCus.Click


    Dim ds1 As New DataSet
    da1.Fill(ds1, "Customers")

    Dim dr As DataRow
    For Each dr In ds1.Tables("Customers").Rows

    lstCus.Items.Add(dr.Item("CompanyName"))

    Next

    End Sub

    End Class

  2. #2
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: How to clear a list box?

    ListBox.Items.Clear()
    Magiaus

    If I helped give me some points.

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