Reputation: 18433
I want to add a item to combobox
which already in bounded with some data.
Code:
Public Sub showSection()
sb = New StringBuilder()
sb.Remove(0, sb.Length)
sb.Append("SELECT DISTINCT Section ")
sb.Append(" FROM Employee ")
sb.Append(" ORDER BY Section")
Dim sqlSection As String = sb.ToString()
da = New SqlDataAdapter(sqlSection, Conn)
da.Fill(ds, "Section")
dt = ds.Tables("Section")
bs.DataSource = dt
With cbSection
.DisplayMember = "Section"
.ValueMember = "Section"
.DataSource = ds.Tables("Section")
.DataBindings.Add("SelectedValue", bs, "Section")
End With
End Sub
But I want add item, like "---All---"
, so this is should be the output.
---All---
HR
Store
Packing
Training
Qc
Qa
Stock
Upvotes: 0
Views: 6922
Reputation: 7082
Here's the simple solution
Dim dr As DataRow = dt.NewRow()
dr("Section") = "---All---"
dr("SectionId") = 0
dt.Rows.InsertAt(dr, 0)
With cbSection
.DisplayMember = "Section"
.ValueMember = "SectionId"
.DataSource = ds.Tables("Section")
.DataBindings.Add("SelectedValue", bs, "Section")
End With
cbSection.SelectedIndex = 0
Upvotes: 1