I am attempting to manipulate a combobox to only show certain values that I desire out of a binding source. Here is the code I currently have.
provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
datafile = "C:\Users\Jacob\Desktop\Halton\HaltonProject.accdb"
connString = provider & datafile
myConnection.ConnectionString = connString
myConnection.Open()
Dim str As String
str = "SELECT * FROM [Employee] WHERE (SP_Level <> 0)"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
Dim dr As OleDbDataReader = cmd.ExecuteReader
Dim Full_Name As String
While dr.Read
Full_Name = dr("Full_Name").ToString
SP_Emp1.Items.Add(Full_Name)
SP_Emp2.Items.Add(Full_Name)
SP_Emp3.Items.Add(Full_Name)
SP_Emp4.Items.Add(Full_Name)
End while
You can have/ use the same DataSource
for each row/skill set, you just need to filter each accordingly. This creates a DataView
for each criteria rather than manually filtering out some from the source or using a new query to create only slightly different sources:
' my fake table
Dim colors As String() = {"Red", "Green", "Blue", "Orange", "White"}
Dim dt As New DataTable
dt.Columns.Add("color", GetType(String))
For Each s As String In colors
dt.Rows.Add(s)
Next
' create a view for each level and bind it
Dim SPView As New DataView(dt, "Color <> 'Red'", "", DataViewRowState.CurrentRows)
ComboBox1.DataSource = SPView
ComboBox1.DisplayMember = "color"
Dim XPView As New DataView(dt, "Color <> 'Green'", "", DataViewRowState.CurrentRows)
ComboBox2.DataSource = XPView
ComboBox2.DisplayMember = "color"
Dim ZPView As New DataView(dt, "Color <> 'Blue'", "", DataViewRowState.CurrentRows)
ComboBox3.DataSource = ZPView
ComboBox3.DisplayMember = "color"