Another day , and another learning, I was trying to add a default value to a combo box bound to an EF result list. Normally we would just create a generic list or some type of your favourite collection from the database and add a empty entry or default entry like “Select All” to the list item with index as 0.
The same applies here the only difference is you have to create a temporary entity object (table) which is going to bind the combo box and add default value to its key and other required parameter. Then bind it to the combo box. The code is given here
Its in C#, the VB version is here
Using context As New SPEntities1 Dim supplier = context.tblSuppliers.Where(Function(x) x.rec_status = "A" And x.type = "S").OrderBy(Function(o) o.supName) Dim lst = supplier.ToList Dim defaultEntry = New tblSupplier defaultEntry.supName = "SELECT" defaultEntry.supCode = "0" lst.Insert(0, defaultEntry) cmbSupplier.DataSource = lst cmbSupplier.DisplayMember = "supName" cmbSupplier.ValueMember = "supCode" End Using
Thanks to Stackoverflow and the OP and ALL Respondents.