Adding items to a ListBox RRS feed

  • Question

  • Hello,

    I have a databound listbox and I want to add an "All items" item to the box. I cannot add items to a databound control. Is there a way around this (while keeping the databinding) ?

    The listbox serves as a filter for a datagrid.


    Monday, February 20, 2006 11:59 AM

All replies

  • The way I always did it was by adding a row to the beginning (position zero) of underlying bound datatable.  The following assumes you have already declared and filled a dataTable named "dt", and that you haven't bound it to the listbox yet.

    Dim row As DataRow

    row = dt.NewRow

    'fill out all the necessary fields for the row to avoid null errors

    row("FieldName") = "(ALL)"

    dt.Rows.InsertAt(row, 0)

    'now bind the datatable to the listbox


    Monday, February 20, 2006 6:31 PM