FlexGrid with C1MultiSelect cell not working

Posted by: alex.corti on 26 May 2022, 5:46 am EST

    • Post Options:
    • Link

    Posted 26 May 2022, 5:46 am EST

    My customer needs to put a multiselection into all the cell of one column his flexgrid.

    This is the portion of my code.

    [i]string comboIdValue = “Id”;

    string comboIdText = “Name”;

    string mycomboTable = “ANA_MEASURES”;

    string comboQuery = “SELECT " + comboIdValue + " ,” + comboIdText + " FROM ( " + mycomboTable + “) cb”;

    switch (comboTable.connection_type.ToLower())

    {

    case “microsoft sql server”:

    dtCombo = microsoftUtil.getDataTable(comboTable.connection_string, comboQuery, ref comboTableColsName, ref _errorMsg);

    break;

    case “oracle”:

    dtCombo = oracleUtil.getDataTable(comboTable.connection_string, comboQuery, ref comboTableColsName, ref _errorMsg);

    break;

    case “mysql”:

    dtCombo = mysqlUtil.getDataTable(comboTable.connection_string, comboQuery, ref comboTableColsName, ref _errorMsg);

    break;

    default:

    break;

    }

    _fgTable.Cols[col].Style = _fgTable.Styles[findCol.col_name];

    if (findCol.cmb_isMultiselection == 0)

    { // Combobox : is working

    Dictionary<string, string> dictionary = new Dictionary<string, string>();

    foreach (DataRow row in dtCombo.Rows)

    {

    string key = (row[0] == DBNull.Value ? “DBNull.Value” : (string)row[0]);

    string value = (row[1] == DBNull.Value ? “” : (string)row[1]);

    dictionary.Add((string)key, (string)value);

    }

    _fgTable.Cols[col].DataMap = dictionary;

    }

    else

    {

    // Multiselect di C1: works only if I map display and data with the samo column name

    C1MultiSelect _multiSelection = new C1MultiSelect();

    _multiSelection.BindingInfo.DataSource = dtCombo;

    _multiSelection.BindingInfo.DisplayMemberPath = comboIdText; // comboIdValue;

    _multiSelection.BindingInfo.DataMember = comboIdValue;

    _multiSelection.SelectionMode = C1.Win.Input.SelectionMode.Multiple;

    _multiSelection.Separator = findCol.cmb_multiselection_separator; // comma

    _multiSelection.DisplayMode = C1.Win.Input.DisplayMode.Text;

    _multiSelection.ShowSelectAll = true;

    _multiSelection.SelectAllCaption = “Tutti”;

    _multiSelection.UnselectAllCaption = “Nessuno”;

    _fgTable.Cols[col].Editor = _multiSelection;

    }[/i]

    The problem is that when i select more than one the multiselection write into the cell the first one description and not all the selection (2,3 and more).

    I expect to see all the descripion separeted by comma and not only the first one.

    And, at the end, when I save the content of the grid the description is saved instead of value.

    I need a help to fix in my code thanks

    Alex

  • Posted 27 May 2022, 5:21 am EST

    Hi Alex,

    As per our understanding of your code, you are using a C1MultiSelect control as an editor in a column and also using DataMap in the same column, and when selecting multiple values from the MultiSelect, the DataMap is not showing the multiple mapped values. This is the designed behavior of the Grid as the DataMap only works if the value of the cell matches the value in the DataMap and the Grid is able to fetch a Mapped value from the DataMap.

    If you want to select Multiple Values from MultiSelect and then show mapped values for those selected values, you can handle the OwnerDrawCell event of the C1FlexGrid, instead of using DataMap in the column.

    In the OwnerDrawCell event, you can manually create a string by fetching the Mapped Values from the DataMap and assigning it to the Text property of the OwnerDrawCellEventArgs. Kindly refer to the attached sample showing the same.

    If you meant something else, please provide a sample showing your implementation and the issue you are facing, so we can investigate accordingly and assist you further.

    MultiSelect_FG_DataMapping.zip

    Best Regards,

    Kartik

  • Posted 27 May 2022, 11:34 am EST

    Hi Kartik,

    I used your example in my application and it is working, but the custemer has expected to see the descritpion into the multiSelect too.

    I’m trying to change your code to obtain customer goal.

    If I don’t find a solution I will give you a feeedback to obtain your help.

    Thanks

  • Posted 27 May 2022, 1:01 pm EST

    Hi Kartik,

    I need your help because I can’t find a solution.

    I suppose that I need your help to individuate the correct event to solve step nr 1:

    1. When multiselect is opening select all the description starting from my codes collected into the flexgridcell.
    2. When multiselect is closed I have to convert the labels into the codes (this event I suppose is C1FlexGrid1_AfterEdit)

    Thanks Alex

  • Posted 30 May 2022, 5:45 am EST

    Hi Alex,

    1. To select your required items in the C1MultiSelect Control when any cell is edited, you can use the SetupEditor event of the C1FlexGrid. In the event, you can use the Row and Col properties of the RowColEventArgs to get the codes in the cell and select the corresponding MultiSelect items by setting their Selected property to true. Please refer to the code snippet below showing an example of you can use the SetupEditor event.
    
    
        private void C1FlexGrid1_SetupEditor(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
            {
                if(c1FlexGrid1.Cols[e.Col].Name == "MultiSelect Column")
                {
                    var collectedCodesInCell = c1FlexGrid1[e.Row, e.Col].ToString().Split(',').ToList();
    
                    foreach (var item in _multiSelect.Items)
                    {    
                        /*here you can check if the value of the MultiSelect item matches
                        any code in Cell and then select/unselect that item accordingly. */
                        if (collectedCodesInCell.Contains(item.Value.ToString()))
                        {
                            item.Selected = true;
                        }
                        else
                        {
                            item.Selected = false;
                        }
                    }
                }
            }
    
    
    
    1. To convert the C1MultiSelect items into codes when C1MultiSelect is closed and store them in the cell, you can use the AfterEdit event of the C1FlexGrid, as shown in the previously shared sample.

    Best Regards,

    Kartik

  • Posted 30 May 2022, 5:49 am EST

    Hi Kartik,

    thanks for your tip. I will try it and I will give you a feedback.

    Alex

  • Posted 30 May 2022, 8:48 am EST

    Hi Kartik,

    I want to confirm you that with your tips and sample code I have reached customer goal.

    Thanks for your help I appreciated it.

    Alex

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels