Created
September 7, 2017 15:57
-
-
Save NPS-ARCN-CAKN/74034dd2b5ee3f6653bd727dd725289e to your computer and use it in GitHub Desktop.
VB .NET: Set up a data bound, code translating DataGridViewComboBox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Sub LoadWorkLogNetworkIDComboBox() | |
'get a reference to the datagridview's combobox column | |
Dim NetworkIDCombobox As DataGridViewComboBoxColumn = Me.TblNetworkWorkLogDataGridView.Columns("WorkLog_NetworkIDComboBox") | |
'set the combobox's datapropertyname to the corresponding column in its bindingsource. this bindingsource was set up using the form's tools, not in code | |
With NetworkIDCombobox | |
'bind the combobox to the NetworkID column of the work log bindingsource's datatable | |
.DataPropertyName = "NetworkID" | |
'load the combobox options from a database query | |
Dim AKROSqlConnection As New SqlConnection(My.Settings.AKROConnectionString) | |
Dim NetworksLookupSqlDataAdapter As New SqlDataAdapter("SElECT NetworkID, Acronym FROM tblNetworks", AKROSqlConnection) | |
Dim NetworksLookupDataTable As New DataTable("NetworksLookup") | |
NetworksLookupSqlDataAdapter.Fill(NetworksLookupDataTable) | |
Dim NetworksLookupBindingSource As New BindingSource | |
NetworksLookupBindingSource.DataSource = NetworksLookupDataTable | |
'load the combobox options with the records from the lookup datatable and translate the NetworkID code to an Acronym | |
.DataSource = NetworksLookupBindingSource | |
.ValueMember = "NetworkID" 'the actual value | |
.DisplayMember = "Acronym" 'the virtual value the user will see | |
End With | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment