Hi,
i am using a Ultragrid - in one Column a UltraComboEditor is used as EditorComponent.The UltraComboEditor is set for multiple selection with checkboxes.
The Problem: the result of the ultracomboeditor is always the DisplayTEXT not the selected VALUES (IDs)
Example of the Content of the List:ID: 100s_Bezeichnung: "Kostenstelle 1"
wrong result: "KostenstelleA; KostenstelleB; KostenstelleC" right result: "100;200;300"
In the Database should be saved the IDs of the CheckedItems: 100;200;300
Definition of the UltraComboEditor:
Me.cboKStValueList.CheckedListSettings.CheckBoxStyle = Infragistics.Win.CheckStyle.CheckBoxMe.cboKStValueList.CheckedListSettings.EditorValueSource = Infragistics.Win.EditorWithComboValueSource.CheckedItemsMe.cboKStValueList.CheckedListSettings.ItemCheckArea = Infragistics.Win.ItemCheckArea.ItemMe.cboKStValueList.CheckedListSettings.ListSeparator = ";"Me.cboKStValueList.DropDownStyle = Infragistics.Win.DropDownStyle.DropDownList
Me.cboKStValueList.DataSource = cls_ZE_global.lstKStMe.cboKStValueList.DisplayMember = "s_Bezeichnung"Me.cboKStValueList.ValueMember = "ID"
Setting the UltraComboEditor as EditorComponent
For Each col As Infragistics.Win.UltraWinGrid.UltraGridColumn In ugResult.DisplayLayout.Bands(0).Columns Select Case col.Key case "s_KSt" col.EditorComponent = cboKStValueList...
Thanks for your help!
Mike Fleisch
i found a dirty solution on my own - but would be glad, if there is a better way
I am using to strings for this
s_KSt_MultiSel ... contains the IDs, read and save from dbs_KSt_MultiSel_Display ... contains the translated Display-Values
After the cell has changed, the original IDs are set manually
Private Sub ugZulagenJeTag_AfterCellUpdate(sender As Object, e As CellEventArgs) Handles ugZulagenJeTag.AfterCellUpdate Try If e.Cell.Column.Key = "" Then Dim cls As cls_ZE_ZulagenJeTag = e.Cell.Row.ListObject If cls IsNot Nothing AndAlso Me.ugZulagenJeTag.Rows(0).Cells("s_KSt_MultiSel_Display").EditorComponentResolved IsNot Nothing Then cls.s_KSt_MultiSel = "" For Each itm As ValueListItem In DirectCast(Me.ugZulagenJeTag.Rows(0).Cells("s_KSt_MultiSel_Display").EditorComponentResolved, UltraComboEditor).CheckedItems cls.s_KSt_MultiSel &= itm.DataValue & ";" Next End If End If Catch ex As Exception Dim errhandler As New ErrorHandler errhandler.HandleError(ex) End Try End Sub
Greets, Mike
The valuelist of the combo has a ValueDisplayStyle that you can set to DataValue.
eg.
(ultraComboEditor1.ValueList as Infragistics.Win.ValueList ).DisplayStyle = ValueListDisplayStyle.DataValue;
Hi Michael,
i don't think that this is something new or anything who nobody needs.I just wand to bind a key/value-list.
The EditorComponent can handle this with a single-selection.Therefore you use the "DisplayMember" and "ValueMember".
Only if you want to use multi-selection this issue occurs.
I think, this should be a default function ....
Hi Mike,
Where, exactly, are you getting the wrong result, then? The way ValueLists work is that every item has a DataValue and a DisplayText. The DisplayText is shown to the user, and the DataValue is used for the value. So the Value of your grid cell should be an array of objects that contain the values corresponding to the items the user picked, and the Text of the cell is a delimited string showing the DisplayMembers. What you are describing IS the default function of the control. So what's not working for you? Where are you getting the DisplayTexts when you want the values?
thanks for your answer.
You're right, if the UltraComboEditor is used as standalone control.I would like to use it as EditorComponent in an UltraGrid.
I have created a simple, quick and dirty Test-Application for that:
Public Class clsItem Public Property nItemID As Integer Public Property sItemName As String Public Property sDescription As String Public Property lstOwner As New List(Of clsUser) End Class Public Class clsUser Public Property nUserID As Integer Public Property nUserName As String End Class Public Class Form1 Dim lstItems As New List(Of clsItem) Dim lstUsers As New List(Of clsUser) Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'Create DEMO-Data For i As Integer = 1 To 10 Dim cItem As New clsItem cItem.nItemID = i cItem.sItemName = "Item " & i lstItems.Add(cItem) Dim cUser As New clsUser cUser.nUserID = i cUser.nUserName = "User " & i lstUsers.Add(cUser) Next 'Settings UltraComboEditor UltraComboEditor1.DataSource = lstUsers UltraComboEditor1.ValueList.DisplayStyle = Infragistics.Win.ValueListDisplayStyle.DisplayText UltraComboEditor1.DisplayMember = "nUserName" UltraComboEditor1.ValueMember = "nUserID" 'Settings UltraGrid UltraGrid1.DataSource = lstItems For Each col As Infragistics.Win.UltraWinGrid.UltraGridColumn In UltraGrid1.DisplayLayout.Bands(0).Columns Select Case col.Key Case "lstOwner" col.CellAppearance.TextHAlign = Infragistics.Win.HAlign.Left col.EditorComponent = UltraComboEditor1 End Select Next End Sub Private Sub UltraButton1_Click(sender As Object, e As EventArgs) Handles UltraButton1.Click Debug.Print(Me.UltraComboEditor1.Value) End Sub End Class
If i use the property clsItem.lstOwner as List(Of clsUser) it will not be displayed in the UltraGrid:
When i change the property clsItem.lstOwner as String the Column is displayed.
Now i get the Data-Types as Result:
Me.UltraComboEditor1.Value: Type is List(Of Object)Me.UltraGrid1.Rows(0).Cells("lstOwner").Value: Type is String ("User2;User4")
The problem here is the DataType of your 'lstOwner' column. There are several problems, in fact.
First, the ValueMember on your UltraComboEditor is "nUserID". So this means the values are the ids of the users, not the entire clsUser class. So even if you could use a List here, it can't be a list of clsUser objects, it would have to be a list of nUserID values, so it would be a list of ints.
Second, the code as you have it here will not even display the 'lstOwner' in the grid, because a List(Of clsUser) or any generic List is interpreted as a child band, not a column. Finally, the UltraComboEditor doesn't produce a generic List, it produces an array. So the correct data type of the column is 'Object()':
Public Property lstOwner As Object()I have attached a working version of your sample here.
WindowsApp8.zip
thanks for your help, that was exactly what i was looking for! Great!