UltraWebGrid: How to use a drop-down list in a column
-
08-06-2019 - |
Question
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.
I tried reading the documentation but Infragistics' documentation is not so good. I've also taken a look at this discussion with no luck.
What I'm doing so far:
col.Type = ColumnType.DropDownList;
col.DataType = "System.String";
col.ValueList = myValueList;
where myValueList
is:
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.
Solution 2
I've found what was wrong.
The column must allow updates.
uwgMyGrid.Columns.FromKey("colTest").AllowUpdate = AllowUpdate.Yes;
OTHER TIPS
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");
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)
{
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow