如何将 Infragistics Ultragrid 列更改为下拉列表?

How do I change a Infragistics Ultragrid Column into a drop down list?

我有一个填充了 SQL 查询的 UltraGrid。其中一列,'groupId' 我想制作一个下拉列表。我也有一个 SQL 查询。 Ultragrid 已填充,但我无法确定下拉列表部分。

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

只需将列的 ValueList 属性 设置为值列表的一个实例,即可为您创建下拉列表。您所需要的只是一个将您的 DataTable 转换为 ValueList 的函数,或者更好的 DataTable 对象的扩展方法,例如这个

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

现在你可以这样调用这个函数了

' 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)
' Call the datatable's extension method 
Dim vl As ValueList = ddt.ToValueList("Id", "Description")

' And finally use the ValueList property from the column
UltraGrid1.DisplayLayout.Bands(0).Columns("groupid").ValueList = vl

但是请注意,您应该 运行 将此代码放在 InitializeLayout 事件中,而不是在网格的数据源初始化之后进行内联。