Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / Multi-Select combo in UltraWinGrid

Multi-Select combo in UltraWinGrid

New Discussion
Tom
Tom asked on Apr 3, 2018 7:57 PM

I need to use a multi-select combo in a grid.  I assume that the cell can’t be databound due to the fact it is multi-select.  My problem is when the grid is bound to a datasource, how do I select the appropriate entries in the grid for each row?  I think the code would go in the InitializeRow event, but I don’t know how to reference the control.  Also, when the data needs to be saved, I don’t know how to reference the control either.

To get the combo in the grid I have done the following: (Windows form project using 17.2)

Added an UltraComboEditor to the form

Added the following code to the form load event

cbeContact.DataSource = _dtContacts;
cbeContact.ValueMember = “Id”;
cbeContact.DisplayMember = “NameTitle”;
cbeContact.DropDownStyle = Infragistics.Win.DropDownStyle.DropDownList;
cbeContact.CheckedListSettings.CheckBoxStyle = Infragistics.Win.CheckStyle.CheckBox;
cbeContact.CheckedListSettings.EditorValueSource = Infragistics.Win.EditorWithComboValueSource.CheckedItems;

Added the following code to the grids InitializeLayout event

e.Layout.Bands[2].Columns.Insert[7,”ContactId2″];
e.Layout.Bands[2].Columns[“ContactId2”].Hidden = false;
e.Layout.Bands[2].Columns[“ContactId2”].Header.Caption = “Contact/Ship To”;
e.Layout.Bands[2].Columns[“ContactId2”].Width = 180;
e.Layout.Bands[2].Columns[“ContactId2”].EditorComponent = cbeContact;

Sign In to post a reply

Replies

  • 0
    Michael DiFilippo
    Michael DiFilippo answered on Mar 30, 2018 6:47 PM

    Hello Tom,

    Thank you for following up. You must set the Value property of the cell to a string which can map to a string property in your dataitems that keep track of the selection. One possible way manually setting the cell values is to convert the ValueListItems to a string array. Then you can use the following code to keep track of the checked items in the ultracomboeditor and create your own string based on the items checked and update the cells respectfully.

    eg.

    private void UltraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
            {
                ValueListItemsCollection items = ultraComboEditor1.ValueList.ValueListItems;
                var checkedItems = items.ValueList.CheckedItems;
                String[] selectedValueListItems;
    
                List intList = new List();
                foreach (ValueListItem item in checkedItems)
                {
                    intList.Add(item);
                }
    
                selectedValueListItems = intList.ConvertAll(p => p.ToString()).ToArray();
               
                e.Row.Cells[1].Value = string.Join(", ", selectedValueListItems);
                
            }

    I attached a sample achieving this below. When you run the sample you will see the ultracomboeditor is intentionally showing with the first two values checked. When you open the second cell’s dropdown you will find that the same items are checked. This was all obtained with the code above.

    Let me know if you have any questions.

    UltraGridComboEditor

    • 0
      Tom
      Tom answered on Apr 2, 2018 1:32 PM

      When I run the code there are no values selected in the first drop down and no other columns have a dropdown?

    • 0
      Tom
      Tom answered on Apr 2, 2018 4:36 PM

      I have tried this:

      //get the values that should be selected

      sql = "SELECT ContactId FROM ContractProductContact WHERE ContractProductId = " + e.Row.Cells[“Id”].Value.ToString();
      DataTable dt = new DataTable();
      Common.GetMeaDataTable(sql, dt);

      String[] selectedValueListItems = new String[dt.Rows.Count];

      //put them in the array
      for (int i = 0; i<dt.Rows.Count;i++)
      {
      selectedValueListItems[i] = dt.Rows[i][“ContactId”].ToString();

      }

      //assign to the cell

      e.Row.Cells[“ContactId2”].Value = string.Join(", ", selectedValueListItems);

      I am not getting any of the values selected in the dropdown

      • 0
        Tom
        Tom answered on Apr 2, 2018 7:31 PM

        The cell was being treated as an integer which made it fail. After making the cell a String, it worked fine.

      • 0
        Michael DiFilippo
        Michael DiFilippo answered on Apr 2, 2018 8:22 PM

        Hello Tom,

        Yes, the sample using a string column. Let me know if you have any additional questions.

    • 0
      Tom
      Tom answered on Apr 3, 2018 1:34 PM

      When I use the above code to get the selected items it always returns the last items that I selected.  If I change row 1, 2 and 3 int the grid, only the selected items from row 3 are returned.  I think I need a way to reference the items in the grid not in the ultraComboEditor.

    • 0
      Tom
      Tom answered on Apr 3, 2018 3:06 PM

      Just to be clear, if I select a different item(s) for the cell, instead of the value being 1,2, it is the display text (option1, option 2) instead of the value? I double checked my code the the displaymember and valuemember for the comboeditor are set correctly.

      • 0
        Michael DiFilippo
        Michael DiFilippo answered on Apr 3, 2018 6:33 PM

        Hi Tom,

        The sample was not intended to keep track of the selection made to the UltraComboEditor that is outside of the UltraGrid. The goal was to "onload" demonstrate how to populate the cells of the UltraGrid with the ValueListItems that are already to be considered checked and stay in sync and between different cells. Please clarify that the selection made to one cell doesn't carry over to another cell.

        Please modify my sample to align with the second issue regarding the display text behavior you are seeing.

        If you desire something additional/different or have any additional questions please let me know.

      • 0
        Michael DiFilippo
        Michael DiFilippo answered on Apr 3, 2018 7:57 PM

        Hi Tom,

        I modified my sample and simplified it to demonstrate how to add unique rows with a string

        eg. “Item 1, Item 2”  (both at design time and runtime) to multi-select values in a combobox field of the UltraGrid.

        eg.

        ultraDataSource1.Rows.Add(new object[] { "test", "Item 4, Item 5, Item 6" });

        Please refer to the attachment below and let me know if you have any questions.

        6052.UltraGridComboEditor

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Tom
Favorites
0
Replies
9
Created On
Apr 03, 2018
Last Post
7 years, 11 months ago

Suggested Discussions

Tags

Created by

Tom

Created on

Apr 3, 2018 7:57 PM

Last activity on

Feb 23, 2026 10:25 AM