Been using Infragistics for over 1 year now. We built a framework around the Winforms controls. We have Comboboxes that need to detect if the value entered exists in the list the box is bound to and prompt if the value is a new value.
Everything has been working great, up until a "fix" was made to the combobox so that if the value entered is not found in the column defined as the display column, the value column is searched. If the value entered is found in the value column, the combobox now points to that row of the list.
It has been suggested to use the ItemNotInList event to trap for this situation. GREAT! However, putting code in this event works fine, except that you can not put any kind of prompt in this method. Once the prompt is hit, the displayed value changes to the row that contains that value in the id column. We need to figure out how to trap for values not found, without changing the displayed value.
Thanks for any help.
Hi,
I tested this out and I don't seem to be getting the same results you are describing.
To test this out, I put an UltraComboEditor on a form with a button. The button does nothing, it's just there so I can take focus away from the combo.
I populated my combo like so:
private void Form1_Load(object sender, EventArgs e) { this.ultraComboEditor1.Items.Add(1, "A"); this.ultraComboEditor1.Items.Add(2, "B"); this.ultraComboEditor1.Items.Add(3, "C"); }
Now, I run the application and type in a "1" into the combo and click on the button.
The combo shows an "A" and the ItemNotInList event does not fire.
So there are two questions:
1) Why is the combo showing an "A"?
The reason for this is because when you type an item into the combo that is not on the list, it has to do something with the text you entered. Normally, it would take what you typed in, find the matching display text and the Value property of the combo would return the matching value on the list. But in the case where there is no matching item no the list, the Text and the Value of the combo both return the same thing - the text you entered.
So when you enter a "1" and there is no item on the list with a DisplayText of "1", the Value and Text of the control get set to "1".
Now... since there is an item on the list whose DataValue is 1, the control translates this into a display text of "A".
The fix you mentioned was for a bug where when the text was not found on the list, the Value of the control was returning null. That was a serious bug that would prevent users from entering anything that was not on the list because when they did so, the Value would be null and then the Text would be cleared out, because there is no null item on the list.You would essentially lose what you typed.
So all of this is as it must be and I don't see any way around it.
2) Why isn't ItemNotInList firing?
This is where I see a problem. When you type a "1" and there's no matching item on the list with a DisplayText of "1", the ItemNotInList event shoudl fire.
What must be happening is that the value of the control has already been set to "1" and the "1" has been translated into an "A" before we determine whether or not to fire the event. This seems like it may be a bug and I'm going to forward this post over to Infragistics Developer Support so that this can be checked out.
Mike,
Here is where we're at currently with this. We have an outstanding case on this:
CAS-24992-G5GZFQ
Not sure if you're the same Michael who's handling that case. But he provided a sample to show what he's proposing as a solution. I'm using the latest hotfix and ItemNotInList is firing.
In Michael's example, the event automatically adds the new value to the list. This is where the problem currently lies. We do not want to auto add new items. We want to provide a prompt to the user to see if they do indeed want to add, or maybe they want to go back because they entered wrong.
As soon as you put any kind of pause in the ItemNotInList event, if the value entered matches something in the value column for the combo, the display changes to the display text that matches that value. This is very disconcerting.
I need a way either before the ItemNotInList event, or in that event to prevent the entered text from getting translated to the display value for the ValueId. So that when the prompt displays, the combo is still showing the value entered.
The problem is that the Value of the control was returning Null when the Text was not found on the list. If this Combo was bound to a DataBase, it would end up saving Null instead of the text the user typed into the field.
Also, the next time the control tried to convert the Value into text, it would lose the Text, because it would not find a null on the list.
If this was working for you in an actual application, then my guess is you must have been using the Combo very briefly as part of a dialog where the user picks a value and then the dialog closes. Because if that dialog stayed open for any length of time or the combo was used in any extended manner, the Text would have been lost.
Hi Perry,
First, the bad news...
After taking a long, hard look at this issue, it looks like there is simply no way for the control to deal with this kind of thing internally. As I said above, there's a logical contradiction here. If the text you enter into the combo is not on the list, then the Value has to return that text. And if that value matches an item in the ValueMember field, it has to get converted.
Having said all that, I took a look at the IsItemInList problem where the text changes when you show a dialog. As I suspected, the issue is not the dialog itself, but just the fact that the Combo is losing focus. So once again, there's nothing the control can do about this internally.
Now, for the good news. I found a pretty simple workaround.
There's only a brief space of time when the dialog is displayed, so you can work around this by changing the Value of the combo during that time to a value that shows the invalid text and at the same time cannot possibly match any items on the list.
I've attached a sample here which demonstrates this. Basically, I created a small class with a constructor that takes in a string. This class overrides the ToString method and returns the specified string. So this is an object that will never match any items on your list, but will display using whatever text you want.
Then in the IsItemInList, I set the Value of the combo to an instance of this class with the invalid text before displaying the MessageBox.
After the MessageBox or dialog returns, I either set the Value of the combo back to the last valid value, or else to the value of the new item I added to the data source.
There's also some extra code in there to disable the ValueChanged event so that it doesn't fire for the temporary object.
Check out the sample and let us know how it goes. :)
Here's some more bad news - by ig v2011.2, your "fix" is broken. If we have a list as described earlier with values of 1, 2, 3 and display texts, respectively, of A, B, C and assign that (DataTable) as a UltraComboEditor DataSource, everything works fine as long as the user sticks to the list. But we all need this control to also accept un-listed values, like when the user is creating a completely new record.
Your attached example no longer works because UltraComboEditor.EventManager is gone. I came up with the same strategy as you in that, when I detect unlisted text, I add that text as a row to the DataSource DataTable and a value of 0. But then as soon as focus is lost, the control reverts to displaying a mere zero and, worse yet, the row that I added in ItemNotInList() before Validating() doesn't show when the list is dropped down.
There's got to be a better and easier way.
What do you mean by "UltraComboEditor.EventManager is gone"? The EventManager hasn't gone anywhere. It's still there. We would never remove a property like that as it would break backward compatibility.
I downloaded my original sample and updated it to 11.2 and tested it and it works just fine. Same as it always did.
I think that my igv2011.2 is installed correctly, but VS IntelliSense doesn't offer UltraComboEditor.EventManager for me and the compiler doesn't permit my reference to it.. So, I'm soldiering on w/out a skip of the ValueChanged event.
As for the rest of my post, it was my bad. I had misspelled the name of the DisplayMember. Trapping the ItemNotInList event and adding the user's input as a DataSource row DOES work for permitting freestyle data entry w/in the UltraComboEditor.
mduff said:I think that my igv2011.2 is installed correctly, but VS IntelliSense doesn't offer UltraComboEditor.EventManager for me and the compiler doesn't permit my reference to it.. So, I'm soldiering on w/out a skip of the ValueChanged event.
I the compiler is telling you that the EventManager does not exist, then something is seriously wrong and I would strongly advise you to see if you can get that resolved, because it's certain to cause you other serious problems down the road.
What error message do you get when you try to refer to the EventManager in code?