Adding Default Value or Empty Value to Entity Framework bound Combo box

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.

MDI Child form Maximize Issue

Occasionally the mdi child form will not maximize although the windowstate property set to maximized in design of the form as well as calling code from MDI like this

 Dim frm As New frmProduct
        frm.MdiParent = Me
        frm.WindowState = FormWindowState.Maximized
        frm.Show()

after some googling around I found out from this link that we have to set the autoscale mode of child form to inherit rather than default Font mode.

Search Inside Datagridview Winforms VB.NET

If txtName.Text <> "" Then
            Dim s As String = txtName.Text.Trim
            dgv.ClearSelection()
            dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect
            Dim someText As String = s
            Dim gridRow As Integer = 0
            Dim gridColumn As Integer = 0
            For Each Row As DataGridViewRow In dgv.Rows
                For Each column As DataGridViewColumn In dgv.Columns
                    Dim cell As DataGridViewCell = (dgv.Rows(gridRow).Cells(gridColumn))
                    If cell.Value.ToString.ToLower.Contains(someText.ToLower) Then
                        ‘cell.Style.BackColor = Color.Yellow
                        dgv.FirstDisplayedScrollingRowIndex = Row.Index
                        dgv.Item(cell.ColumnIndex, cell.RowIndex).Selected = True

                    End If
                    gridColumn += 1
                Next column
                gridColumn = 0
                gridRow += 1
            Next Row
        Else
            dgv.ClearSelection()
        End If

here dgv is datagridview and txtname is the textbox

when you started to type letters in txtname the rows inside the datagridview will be selected based on the letters typed .