Easy Setup of Drop-down Lists in UltraWebGrid
If you’re currently using Infragistics’ UltraWebGrid
and are facing difficulties while implementing a drop-down list in one of your columns, you are not alone. Many developers encounter similar challenges due to the complexities involved in using third-party grid components. While the official documentation can be less than helpful, this guide aims to clarify your path, empowering you to correctly implement a drop-down list in your grid columns.
Understanding the Problem
In your attempt to set up a drop-down list, you may find that the drop-down does not display the expected values. Here’s what you likely have in your code:
col.Type = ColumnType.DropDownList;
col.DataType = "System.String";
col.ValueList = myValueList;
And you might have constructed myValueList
like this:
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)
}
However, the cells in your column appear empty when rendered on the page. What could possibly be going wrong?
Solution: Allow Column Updates
The issue often boils down to one simple yet crucial detail: the column must allow updates. If updates are not allowed, the UltraWebGrid
will not properly render the drop-down list.
Here’s how to enable updates for your column:
You need to set the AllowUpdate
property for the specific column to Yes
. This can be done with the following line of code:
uwgMyGrid.Columns.FromKey("colTest").AllowUpdate = AllowUpdate.Yes;
Putting It All Together
To ensure that your drop-down list appears correctly, incorporate the following steps:
- Define Your Drop-down Column: As you’ve done.
- Set the ValueList: Like you’ve done with
myValueList
. - Enable Updates: Make sure to add the
AllowUpdate
setting to your column configuration.
Example Code
Here is a consolidated example:
// Setup column
col.Type = ColumnType.DropDownList;
col.DataType = "System.String";
col.ValueList = myValueList;
// Allow updates for the column
uwgMyGrid.Columns.FromKey("colTest").AllowUpdate = AllowUpdate.Yes;
// Creating the ValueList
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);
}
Conclusion
Implementing a drop-down list in the UltraWebGrid
can be a tricky task, but with this checklist and code examples, you should be able to overcome the challenges. Remember, always ensure that updates are enabled for the column—it’s often the little things that make a big difference!
With this approach, you should now see the desired drop-down lists populated in your grid cells. If you encounter any further issues, revisiting your grid and column properties might help resolve any lingering problems.