这可能会有所帮助。它是一个简单的过程,它接收 DataTable、ValueList 的 Key 属性的值以及用作 ValueList 列表的字段名称,并返回要在 UltraGridColums 中设置的值列表
public ValueList DataTableToValueList(DataTable dt, string vlKey, string fieldName)
{
ValueList vl = new ValueList();
if (!string.IsNullOrEmpty(vlKey)) vl.Key = vlKey;
foreach (DataRowView r in dt.DefaultView)
vl.ValueListItems.Add(r[fieldName]);
return vl;
}
这样使用(可能在InitializeLayout事件中)
grd.DisplayLayout.Bands[0].Columns["col"].ValueList =
DataTableToValueList(dtCustomers,"vlCustomer", "CustomerName");