C# UltraWebGrid:如何在列中使用下拉列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UltraWebGrid: How to use a drop-down list in a column
提问by mbillard
I'm using the Infragistics grid and I'm having a difficult time using a drop-down list as the value selector for one of my columns.
我正在使用 Infragistics 网格,但在使用下拉列表作为其中一列的值选择器时遇到了困难。
I tried reading the documentation but Infragistics' documentation is not so good. I've also taken a look at this discussionwith no luck.
我尝试阅读文档,但 Infragistics 的文档不太好。我也看了看这个讨论,但没有运气。
What I'm doing so far:
到目前为止我在做什么:
col.Type = ColumnType.DropDownList;
col.DataType = "System.String";
col.ValueList = myValueList;
where myValueList
is:
在哪里myValueList
:
ValueList myValueList = new ValueList();
myValueList.Prompt = "My text prompt";
myValueList.DisplayStyle = ValueListDisplayStyle.DisplayText;
foreach(MyObjectType item in MyObjectTypeCollection)
{
myValueList.ValueItems.Add(item.ID, item.Text); // Note that the ID is a string (not my design)
}
When I look at the page, I expect to see a drop-down list in the cells for this column, but my columns are empty.
当我查看页面时,我希望在此列的单元格中看到一个下拉列表,但我的列是空的。
采纳答案by mbillard
I've found what was wrong.
我发现出了什么问题。
The column must allow updates.
该列必须允许更新。
uwgMyGrid.Columns.FromKey("colTest").AllowUpdate = AllowUpdate.Yes;
回答by Erick B
Here's an example from one of my pages:
这是我的一个页面中的示例:
UltraWebGrid uwgMyGrid = new UltraWebGrid();
uwgMyGrid.Columns.Add("colTest", "Test Dropdown");
uwgMyGrid.Columns.FromKey("colTest").Type = ColumnType.DropDownList;
uwgMyGrid.Columns.FromKey("colTest").ValueList.ValueListItems.Insert(0, "ONE", "Choice 1");
uwgMyGrid.Columns.FromKey("colTest").ValueList.ValueListItems.Insert(1, "TWO", "Choice 2");
回答by regor
public void MakeCellValueListDropDownList(UltraWebGrid grid, string columnName, string valueListName, string[] listArray)
{
//Set the column to be a dropdownlist
UltraGridColumn Col = grid.Columns.FromKey(columnName);
Col.Type = ColumnType.DropDownList;
Col.DataType = "System.String";
try
{
ValueList ValList = grid.DisplayLayout.Bands[0].Columns.FromKey(columnName).ValueList;
ValList.DataSource = listArray;
foreach (string item in listArray)
{
ValList.ValueListItems.Add(item);
}
ValList.DataBind();
}
catch (ArgumentException)
{
}
}