我有一个的UltraGrid填充了一个SQL查询。其中一列,“群ID”我想作一个下拉列表。我有一个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
只要您的列值列表属性设置为一个值列表的一个实例将创建下拉你。所有你需要的,把你的数据表中值列表或更好的扩展方法的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事件中的代码,而不是网格的数据源的初始化之后做内联。