Tuesday 12 March 2013

VB.NET - Add empty record to ComboBox

  Me.Payment.Items.Insert(0, String.Empty) - ASP.NET
 you will get the following error if you try to execute this on regular (not asp.net) application

Items collection cannot be modified when the DataSource property is set

To fix it create empty row, add some empty data to it, and then add this row to dataset

        Dim drEmpty As DataRow = Ds.Style_Payment.NewRow
        drEmpty("paymentId") = -1 : drEmpty("paymentName") = ""
        Ds.Payment.Rows.InsertAt(drEmpty, 0)
        Ds.Payment.AcceptChanges()

No comments:

Post a Comment