adding an item and clearing all items

2 posts, 0 answers
  1. Simon
    Simon avatar
    7 posts
    Member since:
    Sep 2011

    Posted 21 Sep 2011 Link to this post

    Private Sub LoadSupplierCombo()
            Cursor = Cursors.WaitCursor
            tsstatus.Text = "Loading Suppliers, please wait..."
            Refresh()
            '     cbSuppliers..MasterTemplate.AutoGenerateColumns = True
     
            Dim TicketsDA As SqlDataAdapter
            Dim TicketsDS As DataSet
            Dim TicketsDV As DataView
            Dim SQLString As String = ""
     
     
            DBOpen()
            Try
     
                SQLString = "SELECT     Supplier.SupplierName AS Supplier, Supplier.SupplierAccountNo AS [Account No] " & _
    "FROM         SZTickets INNER JOIN " & _
                         " SZTicketStatus ON SZTickets.statusId = SZTicketStatus.id INNER JOIN " & _
                         " SZTicketPriority ON SZTickets.priorityId = SZTicketPriority.id INNER JOIN " & _
                         " Supplier ON SZTickets.supplierId = Supplier.SupplierID " & _
    "GROUP BY Supplier.SupplierName, Supplier.SupplierAccountNo " & _
    "ORDER BY Supplier DESC"
     
                Dim SQLcmd As New SqlCommand(SQLString, cnn1)
                TicketsDA = New SqlDataAdapter(SQLcmd)
                TicketsDS = New DataSet
                TicketsDV = New DataView
     
                TicketsDA.Fill(TicketsDS, "Suppliers")
                TicketsDV.Table = TicketsDS.Tables("Suppliers")
     
     
                cbSuppliers.DataSource = TicketsDV
     
                SQLcmd.Dispose()
                TicketsDA.Dispose()
     
     
     
     
            Catch ex As Exception
                g_error.DBErrorMsg("Failure to load tickets", SQLString, ex)
            Finally
                dgTickets.ResumeLayout()
                DBClose()
            End Try
            Cursor = Cursors.Default
            tsstatus.Text = ""
     
            Dim columns As RadMultiColumnComboBoxElement = cbSuppliers.MultiColumnComboBoxElement
     
            For Each column As GridViewDataColumn In columns.Columns
                column.BestFit()
            Next
     
            
        End Sub


    Hi

    The above code loads my multi-column list box. However I would like to add <All Suppliers> at the beginning of the list as well as the supplier. I would like this to be the item selected on load.


    Also, I cant find the equivalent command for combobox.items.clear() 

    How do I remove all the items?

    Cheers

    Baz
  2. Svett
    Admin
    Svett avatar
    728 posts

    Posted 26 Sep 2011 Link to this post

    Hi Simon,

    You should add the item before binding the RadMultiColumnComboBox to your data source. You can do it by using the following code snippet:

    Dim table As DataTable = Me.GetDataSource()
     
    Dim row As DataRow = table.NewRow()
    row("ID") = -1
    row("CompanyName") = "All"
     
    table.Rows.InsertAt(row, 0)
     
    Me.radMultiColumnComboBox1.DisplayMember = "CompanyName"
    Me.radMultiColumnComboBox1.ValueMember = "ID"
    Me.radMultiColumnComboBox1.DataSource = table

    You can not clear rows directly by using the Clear method of the rows collection when the controls is in bound mode. Nevertheless, you can iterate through the rows and delete each of them:
    Dim rows As New List(Of GridViewRowInfo)(Me.radMultiColumnComboBox1.EditorControl.Rows)
     
    For Each rowInfo As GridViewRowInfo In rows
        rowInfo.Delete()
    Next

    I hope this helps.

    All the best,
    Svett
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top