我有一个用SQL查询填充的UltraGrid。列之一,“ groupId”,我想创建一个下拉列表。我也有一个SQL查询。 Ultragrid已填充,但我无法确定dropdownlist部分。
Private Sub LoadGrid()
' This is the table for the whole grid
Dim sSql As String = "SELECT [categoryId], [groupId], [sortOrder], [active], [compositeGroup], [multipleValues] FROM [cp].[ec_category_metadatagroup]"
Dim dt As DataTable = mobjGlobals.GetData(sSql, ConfigLookup.ApiKey).Tables(0)
UltraGrid1.DataSource = dt
' This is the table for the groupId DropDownList Column
sSql = "SELECT Id, Description FROM [cp].[ec_metadata_subgroup]"
Dim ddt As DataTable = mobjGlobals.GetData(sSql, ConfigLookup.ApiKey).Tables(0)
End Sub
答案 0 :(得分:2)
只需将列的ValueList属性设置为值列表的实例,即可为您创建DropDown。您所需要做的只是一个将DataTable转换为ValueList的函数,或者更好的是像这样的DataTable对象的扩展方法
Option Explicit
Sub OpenFilesVBA()
Dim Wb As Workbook
Dim strFolder As String
Dim strFil As String
Dim fso As Object
Dim fil As Object
Dim fldr As Object
Application.ScreenUpdating = False
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder(Application.ActiveWorkbook.Path)
For Each fil In fldr.Files
If LCase(fso.GetExtensionName(fil.Path)) = "xlsx" Then
Set Wb = Workbooks.Open(fil.Path)
'===========Run Objective Macro==========================================
Call PoG_Report_Prep
'========================================================================
ActiveWorkbook.Save
Wb.Close False
Set Wb = Nothing
End If
Next
Set fil = Nothing
Set fldr = Nothing
Set fso = Nothing
Application.ScreenUpdating = True
End Sub
现在您可以通过这种方式调用此功能
Module DataTableExtensions
<Extension()>
Public Function ToValueList(dt As DataTable , valueMember As String, displayMember As String) As ValueList
Dim vl As ValueList = New ValueList()
' We follow the sort order set on the DataTable
For Each r In dt.DefaultView
vl.ValueListItems.Add(r(valueMember), r(displayMember))
Next
Return vl
End Function
End Module
但是请注意,您应该在InitializeLayout事件中运行此代码,而不是在初始化网格的DataSource之后内联。