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: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.
Are you using the SAME numeric type for both? (Int32)0 is not equal to (Int64)0 in DotNet.
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.
This indicates that the Value of the control does not match the value on the list. If they are different data types, that would explain why.
shmuly said: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'm not sure I follow what you are saying, but once again, it sounds like something is not matching up properly.
If this doesn't help, then I recommend that you create a small sample project demonstrating the problem(s) and Submit an incident to Infragistics Developer Support so they can check it out and see what's going on.
I'm having the exact same problem. I think this happens when binding to an object with a numeric datatype that is nullable on the database side, but not in the object, which .NET does not allow by default.
We've had this problem with DateTime properties and have had to convert them to Nullable DateTime properties in order to resolve it. I'm thinking we'll try the same thing with numeric types when those types are not required fields and need to have the option of storing in the database as NULL values.
The funny thing is, however, if I put a dummy description in the DisplayValue, such as 'test', the combo box works fine - it's only with an empty string that it attempts to display the data value as the display value.
Mike,
Try this:
Create a class/object in vb.net with these two properties:
Public
Property Code() As Integer
Property Text() As System.String
Put a combo editor on a form and fill it like this:
Dim
lst As New List(Of CodeObject)
Dim Code1 As New CodeObject(0, "")
lst.Add(Code1)
Dim Code2 As New CodeObject(1, "test 1")
lst.Add(Code2)
Dim Code3 As New CodeObject(2, "test 2")
lst.Add(Code3)
The only way I'm able to work around this is to feed my object list into a custom code class that uses a string as the code property and I must set the displaymember of the 'blank row' at least 1 character wide.
Hi,
I tried to set up a sample using your code here and it seems to work perfectly fine for me. What do I need to do to get a problem to occur? It does not appears that this code is using any nullable types, either, so I'm really not sure how that comes into it.