I am binding my value list to a DataTable. In order to provide the user with a blank line, I add a row to the DataTable where all the fields are an empty string except the value field is a 0. When the user selects a value and then tries to change it back to the blank value, as soon as they tab out of the field, the original value is selected.
It's hard to guess without seeing the behavior, but it sounds like you are also binding the edit portion of the control (the Value property) and that the data source eitherdoesn't allow a 0 value or else maybe the 0 is the wrong data type.
Thanks for the reply.
Here is the full scenario:
To load the value list, I am loading a DataTable with values from SQL Server. I then add another row to the DataTable to give the user an option to select a blank value. I then detect the data type of the value field. If it's a numeric data type I set the value of the value field in the blank row to 0. I set the value in the Display field to an empty string. I also bind the edit portion to a business object to a numeric property.
Problem 1 - The value shows up as 0 in the combo. I was able to overcome this by setting the DisplayStyle of the value list to Text. In my opinion this is a mistake in the control. If I set an empty string, it should show. Using reflector, I was able to see that it's treating empty string and Null the same.
Problem 2 - If the display field is set to an empty string, once I select a real value, I cannot select the empty string. The control tries to interpert it as a number and causes a format exception.
I was able to come up with a work-around as follows. I set the display of the blank row to a space. I can then select that row. The only problem I still had was if the user manually blanks out the text in the editor. To overcome that, I manually check the text of the control before leaving the control. If it's an empty string, I set it to a space. Definitely not what I wanted but I have to get it to work.
Please let me know what more information I can provide to help diagnose this problem.
shmuly said: Problem 1 - The value shows up as 0 in the combo. I was able to overcome this by setting the DisplayStyle of the value list to Text. In my opinion this is a mistake in the control. If I set an empty string, it should show. Using reflector, I was able to see that it's treating empty string and Null the same. Problem 2 - If the display field is set to an empty string, once I select a real value, I cannot select the empty string. The control tries to interpert it as a number and c***a format exception.
Problem 2 - If the display field is set to an empty string, once I select a real value, I cannot select the empty string. The control tries to interpert it as a number and c***a format exception.
The Infragistics.Win.ValueListItem class (which encapsulates the items displayed by the UltraComboEditor) exposes two properties, DataValue and DisplayText. The former is of type object, the latter of type string. When you don't specify a value for the DisplayText property, the ToString() method (of the object the DataValue property references) is called to determine what to display. Setting the DisplayText property to either null or an empty string will cause the string representation of the DataValue to be used; an item's resolved text can never be an empty string.
Thanks for the information, Brian!
I do feel that this is a limitation in the control. Having the ability to leave a non-required field blank is a common scenario and it's a little awkward for users when they are tabbing through data entry feilds and there is a 1 character space in there. However, it shouldn't be too difficult to work around this and I'm hoping to hide it from the user now that I know exactly what's going on.
There is a way to owner draw the items; you handle the ValueList's DrawValueListItem event, and in this case, when the ValueListItem's DisplayText is null or empty, set the DoDefaultDrawing property of the event arguments to true, and nothing will be drawn for that item.