I am using Business Objects with NHibernate to poplulate an UltraComboEditor. The editor is set as a drop down and limited to the list. I retrieve my List of objects and bind it to the Editor. I would like to provide the user a "Please Select" prompt as the first (Zero Index) of the drop down and am trying to determine the 'best' means to do this. I have attempted to do a UltraComboEditor.Items.Insert(0, New ValueListItem("Choose","Please Select") but recieve an error that the valuelist cannot be altered after bind. I cannot 'add' it to my intitial list of objects before bind as this will cause error later on in trying to access a non-existant object. Is there an option besides doing a loop through of my list to do an "Add" to the valuelist?
Here is my current code which is not working
Dim lstFS as IList(Of FieldSystem) = FieldSystemFactory.GetAll() uceFieldSystem.ValueMember = "FieldSystemId" uceFieldSystem.DisplayMember = "Name" uceFieldSystem.DataSource = lstFS uceFieldSystem.Items.Insert(0, New ValueListItem("Choose", "Please Select a Field System"))
Dim lstFS as IList(Of FieldSystem) = FieldSystemFactory.GetAll()
uceFieldSystem.ValueMember = "FieldSystemId"
uceFieldSystem.DisplayMember = "Name"
uceFieldSystem.DataSource = lstFS
uceFieldSystem.Items.Insert(0, New ValueListItem("Choose", "Please Select a Field System"))
My thanks in advance for help in determining the best means to accomplish this task.
Does the "Please Select" text need to be an item on the list? If so, then there's no way to do this other than adding that item to the data source. Or... you could use the control unbound and add the items from your data source in a loop.
If the item doesn't need to appear on the list, then maybe all you need to do is set the NullTextLabel. I'm not sure if that works when using DropDownList mode, but I think it might.
If not, another option would be to use a DrawFilter or CreationFilter to simply display some text when the Value of the control is null.
is there any other way to do this? I must need to add "--Select--" as an item in the dropdown.
No. As Mike said, the only way to accomplish this is to add the items to the source that the combo is bound to, though you could use his other suggestion of copying the items of your bound source into a new source that has the "--Select--" option.
-Matt
I solved my issue by following Mike's advice of using the control unbound and adding the items from my datasource in a loop. I have validation before any saves to ensure the Selected Index is not Zero. Here is the code I am using to accomplish this
uceFieldSystem.Items.Add("0", "Please Select a Field System")
uceFieldSystem.Items.Add(itmFS.FieldSystemId, itmFS.Name)
Next
uceFieldSystem.SelectedIndex = 0
thanks for sharing this.
do you think its a good solution? my screen is having about 20 dropdowns and for every drop down adding and loop the items is tedious and costly as sometimes each of the ilist may have 50s to 100s of items.
this is pretty much easy with normal combobox but not in infragistics. definitely this is a "feature request".
Arun.K.S
Hi Arun,
How is this easier with the "normal" combobox? I am not aware of any way to add an extra item into a bound ComboBox control.
50 or 100 items probably is not a big deal, even with 20 dropdowns. Is this actually causing a performance problem with your application? Or are you just worried that it might?