Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1834
What is the best way to select a ValueList item in the code when loading data?
posted
Folks,

I have successfully used UltraDropDowns in WinGrids and am able to preselect the appropriate value in a grid's InitializeRow event.

However, with the simple case of ValueLists, I'm having a bit of trouble. What is the best way to go about selecting the right ValueItem when loading data?

Specifically, we record statuses for particular field with a single character and there's only 4 options ('I', 'E', 'M', and null). Each letter translates to a word, and my approach so far has been to add all the words as ValueListItems in the InitializeRow event:

//add value list for statuses
ValueList vlStatuses = null;
if (!e.Layout.ValueLists.Exists("STATUS_VALUE_LIST"))
{
vlStatuses = e.Layout.ValueLists.Add("STATUS_VALUE_LIST");
vlStatuses.ValueListItems.Add(" ");
vlStatuses.ValueListItems.Add("Missing");
vlStatuses.ValueListItems.Add("Extracted");
vlStatuses.ValueListItems.Add("Impacted");
}
else
{
vlStatuses = e.Layout.ValueLists["STATUS_VALUE_LIST"];
}
In the InitializeRow event for the grid, the code looks like this:

temp = e.Row.Cells["STATUS"].Value;
if (temp != null && temp != DBNull.Value)
{
switch (temp.ToString())
{
case "I":
e.Row.Cells["STATUS"].Value = "Impacted";
break;
case "E":
e.Row.Cells["STATUS"].Value = "Extracted";
break;
case "M":
e.Row.Cells["STATUS"].Value = "Missing";
break;
default:
e.Row.Cells["STATUS"].Value = " ";
break;
}
}
else
e.Row.Cells["STATUS"].Value = " ";


Is there a better way to do this? The knowledgebase article on the subject of ValueLists, UltraDropDowns, and UltraCombos being used in UltraGrids completely ignores any description of how to load data into these controls.

Thanks for your time,
J

P.S.--Am I the only one who had to add html break tags to get a carriage return when posting? Everything I wrote was all jumbled together, with none of my Enter strokes actually resulting in a newline.
Parents
  • 2334
    Verified Answer
    posted
    ValueList items have a DisplayText and a Value property. Set the Value property to I, E, M, null and the DisplayText to Impacted, Extracted, Missing and " ".

    vlStatuses.ValueListItems.Add(null, " "); // or DBNull.Value... not sure which you are using
    vlStatuses.ValueListItems.Add("M", "Missing");
    vlStatuses.ValueListItems.Add("E", "Extracted");
    vlStatuses.ValueListItems.Add("M", "Impacted");
Reply Children