Hi all,
I'm using an UltraComboEditor as an editor in an UltraWinGrid to make a translation "Internal ID" <-> "User Key". The UltraComboEditor has a DataTabe as the DataSource:
ID Key100 1101 2102 3... ....201 100Entering data:DisplayMember ValueMember 1 -> 1002 -> 101 100 -> 100 WRONG201 -> 201 WRONG
What do I have to do the only Values in the key-list are accepted and correctly translated? DisplayMember ValueMember 1 -> 1002 -> 101 100 -> 201201 -> Not accepted
Hello masch,
A possible approach to achieve this might be by hooking to the 'BeforeCellUpdate' event and do something like the following:
bool isItemInList = false; private void ultraGrid1_BeforeCellUpdate(object sender, Infragistics.Win.UltraWinGrid.BeforeCellUpdateEventArgs e) { foreach(ValueListItem item in ultraComboEditor1.Items) { if(item.DisplayText == e.Cell.Text) { isItemInList = true; break; } } if (!isItemInList) { e.Cancel = true; } }
bool isItemInList = false; private void ultraGrid1_BeforeCellUpdate(object sender, Infragistics.Win.UltraWinGrid.BeforeCellUpdateEventArgs e) { foreach(ValueListItem item in ultraComboEditor1.Items) { if(item.DisplayText == e.Cell.Text) { isItemInList = true; break; } }
if (!isItemInList) { e.Cancel = true; } }
Please feel free to let me know if I misunderstood you or if you have any other questions.
Hi Boris,
Thank you for your quick reply. Your solution can solve a part of the problem, but only by correcting a wrong behaviour.In the case where I have 1 in the display which means 100 in the value, and I enter 100 I don't get a CellUpdate-Event, because the UltraCombo "thinks" there is already 100 and therefore no data change.
In my opinion there is a general design error: why does the UltraComboEditor look up in the value-members? Even more it looks first in the value-members, and then in the display-members!
Maybe there is a flag which limits the UltraComboEditor to consider only the display-members?
Regards
Manuel
P.S: I'm using V 10.3 and V 11.2
I have a satisfying solution now, thank you and Mike!
Hello Manuel,
Could you please let me know if you were able to resolve your issue per Mike's suggestions.
Feel free to ask if something comes up.
Hi Mike,
You got it right. I can enter 201 which is not in the DisplayMember column and the UltraComboEditor accepts it as a ValueMember. In my opinion not quite a correct behaviour, but I can hadle this by code. Setting LimitToList doesn't change anything.
Hi Manuel,
masch said:In my example I can enter 201 and it is translated into the pair 100 - 201, displayed is 100.
I'm not sure I am following you. But this might be a problem because of how the control responds when the value you enter does not exist on the list of DisplayMembers.
If you enter something that does not exist in the DisplayMember column, then there is no way for the combo to translate that text into a Value. In such a case, the Value property returns the Text you typed.
So if you type in something that doesn't have a matching DisplayMember value, the Value is set to the whatever you typed. If that value exists on the DataMember list, then there is no way for the control to know that the value came from the text. It's essentially the same as setting the Value to 201.
I suppose you could handle this by setting LimitToList to true and thus preventing the user from typing in anything that doesn't match a DisplayMember.
This helps a lot, nearly perfect!
The only point is, that the UltraComboEditor still looks up in the value-list, if the key entered does not exist in the display-list, but only as a last resort. In my example I can enter 201 and it is translated into the pair 100 - 201, displayed is 100. Entering 100 is correctly translated into 201.I think I can handle this by code. It would be nice if that would not be necesary.
Many thanks!
P.S: The value-list is of type Int, the display-list of type string.