Last active
October 13, 2017 19:30
-
-
Save NPS-ARCN-CAKN/1df46d016b382d02b765294c323e2868 to your computer and use it in GitHub Desktop.
Function to set up a GridEX column with dropdown values
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
''' <summary> | |
''' Loads distinct items from a DataTable's DataColumn into a GridEX GridEXColumn's DropDown ValueList | |
''' </summary> | |
''' <param name="GridEX">The GridEX containing the GridEXColumn requiring a DropDown ValueList</param> | |
''' <param name="SourceDataTable">Name of the DataTable containing the DataColumn from which distinct values will be drawn</param> | |
''' <param name="SourceColumnName">Name of the source DataTable's DataColumn from which distinct values will be drawn</param> | |
''' <param name="GridEXColumnName">Name of the GridEX column into which to load dropdown values</param> | |
Private Sub LoadGridEXDropDown(GridEX As GridEX, SourceDataTable As DataTable, SourceColumnName As String, GridEXColumnName As String, LimitToList As Boolean) | |
Try | |
'Ensure the GridEXColumn is configured for a DropDown | |
With GridEX.RootTable.Columns(GridEXColumnName) | |
.EditType = EditType.Combo | |
.HasValueList = True | |
.LimitToList = False | |
.AllowSort = True | |
.AutoComplete = True | |
.ValueList.Clear() | |
End With | |
'Make a GridEXValueListItemCollection to hold the distinct items | |
Dim ItemsList As GridEXValueListItemCollection = GridEX.RootTable.Columns(GridEXColumnName).ValueList | |
'Get the distinct items from a DataTable | |
Dim DistinctItemsDataTable As DataTable = SourceDataTable.DefaultView.ToTable(True, SourceColumnName) | |
'Sort the DataView | |
Dim DistinctItemsDataView As New DataView(DistinctItemsDataTable, "", SourceColumnName, DataRowState.Unchanged) | |
'Add the distinct items from the DataView into the GridEXValueListItemCollection | |
If DistinctItemsDataView.Table.Rows.Count > 0 Then | |
For Each Row As DataRow In DistinctItemsDataView.Table.Rows | |
If Not IsDBNull(Row.Item(SourceColumnName)) Then | |
Dim Item As String = Row.Item(SourceColumnName) | |
ItemsList.Add(Item, Item) | |
End If | |
Next | |
End If | |
Catch ex As Exception | |
MsgBox(ex.Message & " (" & System.Reflection.MethodBase.GetCurrentMethod.Name) | |
End Try | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment