Here is a quick and easy way of populating a combo box control with a specific SalesLogix picklist’s values.
First, you can use the Picklist class in the Sage.SalesLogix.Picklists.dll assembly.
Lets say I have a picklist called “Vendor”. To retrieve these values I can call this one line, using the GetPicklistItemsByName function:
System.Collections.Generic.IList<Sage.SalesLogix.PickLists.PickList> picklists = Sage.SalesLogix.PickLists.PickList.GetPickListItemsByName("Vendor", true);
Note that the function takes 2 parameters, the picklist you want to retrieve values for and a Boolean switch of returning the list in alphabetic order.
Now with that I can simply set a combo box’s DataSource property and call DataBind:
ComboBox1.DataSource = picklists;
ComboBox1.DataBind();
One other thing to note, it is typically a good idea to initialize a combo box with a blank line so that the user is forced to choose something. You can do this via a line like this:
ComboBox1.Items.Insert(0, new ListItem(" ", " "));
The other thing to consider with doing something like that is that in order to allow a combination of manually inserted list items and a data bound list you need to set a property of the list box to allow appending data bound items after manually added items. This looks like:
ComboBox1.AppendDataBoundItems =true;
Lets look at a full sample:
ComboBox1.Items.Clear();
ComboBox1.Items.Insert(0, new ListItem(" ", " "));
System.Collections.Generic.IList<Sage.SalesLogix.PickLists.PickList>
picklists =
Sage.SalesLogix.PickLists.PickList.GetPickListItemsByName("Vendor",
true);
ComboBox1.DataSource = picklists;
ComboBox1.DataBind();