FlexGrid: Datamap for a column OR editing a text not within the datamap

Posted by: andreas.kren on 15 May 2019, 7:31 am EST

    • Post Options:
    • Link

    Posted 15 May 2019, 7:31 am EST

    Hi,

    I would need to realize the possibilty for a cell (column) to select an entry from a datamap OR edit a (free) text in that Cell.

    The grid is bound to a bindingsource if that is relevant.

    Thank you for help.

  • Posted 16 May 2019, 3:09 am EST

    Hello,

    The DataMap property allows implementing “translated” rows/columns. But if the new value is not in DataMap then this value will not be displayed.

    To resolve this, you can add non-existing values to DataMap before finishing edit (in C1FlexGrid’s ValidateEdit event).

    I’ve attached a sample application to this post for reference. The columns ‘CategoryID’ and ‘SupplierID’ have been set up in a way that their drop-down shows translated values and they also allows entering new values.

    Regards,

    Ruchir

    DataMap_AllowNewValues.zip

  • Posted 17 May 2019, 12:08 pm EST

    If I enter a non-existent value in the mentioned columns and end the editing with the value is not display in the column cell.

  • Posted 20 May 2019, 8:10 am EST

    In the reference example I meant with my last comment?!

  • Posted 20 May 2019, 8:30 am EST - Updated 3 October 2022, 11:27 pm EST

    Hi,

    I do not observe the same at my end. Entering new values (non-existent) in the two columns and moving away by pressing Enter key, the new values persist in the cell. See attached video.

    Is this the same that you’re doing and observing different results?

    In that case, what ComponentOne version are you using? I tested this with latest version of ComponentOne.

    Thanks,

    Ruchir

  • Posted 22 December 2020, 9:30 am EST - Updated 3 October 2022, 11:28 pm EST

    Hi Ruchir,

    I’ve tried to adapt your example to our code (with C1.Win.C1FlexGrid.4.5.2.) as follows:

    
            private int _lastEbenenKeyTmp = -1;
            private int _lastGruppenKeyTmp = -1;
            private void flexListeGeraete_ValidateEdit(object sender, ValidateEditEventArgs e)
            {
                switch (1)
                {
                    case 1 when e.Col == flexListeGeraete.Cols["EbeneId"].Index:
                        if (flexListeGeraete.Editor is ComboBox ebenenCombobox)
                        {
                            var ebenenBezeichnung = ebenenCombobox.Text;
                            if (string.IsNullOrEmpty(ebenenBezeichnung))
                            {
                                return;
                            }
                            object[] ebenenMap = new object[flexListeGeraete.Cols["EbeneId"].DataMap.Values.Count];
                            flexListeGeraete.Cols["EbeneId"].DataMap.Values.CopyTo(ebenenMap, 0);
    
                            if (!ebenenMap.Contains(ebenenBezeichnung))
                            {
                                flexListeGeraete.Cols["EbeneId"].DataMap.Add(_lastEbenenKeyTmp, ebenenBezeichnung);
                                ((DtoGeraete)bindingSourceGeraete.Current).EbeneId = _lastEbenenKeyTmp;
                                ((DtoGeraete)bindingSourceGeraete.Current).Ebene.Id = _lastEbenenKeyTmp;
                                ((DtoGeraete)bindingSourceGeraete.Current).Ebene.Bezeichnung = ebenenBezeichnung;
                                _lastEbenenKeyTmp--;
                            }
                        }
                        break;
    
                    case 1 when e.Col == flexListeGeraete.Cols["GruppeId"].Index:
                        if (flexListeGeraete.Editor is ComboBox gruppenCombobox)
                        {
                            var gruppenBezeichnung = gruppenCombobox.Text;
                            if (string.IsNullOrEmpty(gruppenBezeichnung))
                            {
                                return;
                            }
                            object[] gruppenMap = new object[flexListeGeraete.Cols["GruppenId"].DataMap.Values.Count];
                            flexListeGeraete.Cols["GruppenId"].DataMap.Values.CopyTo(gruppenMap, 0);
    
                            if (!gruppenMap.Contains(gruppenBezeichnung))
                            {
                                flexListeGeraete.Cols["GruppenId"].DataMap.Add(_lastGruppenKeyTmp, gruppenBezeichnung);
                                ((DtoGeraete)bindingSourceGeraete.Current).GruppeId = _lastGruppenKeyTmp;
                                ((DtoGeraete)bindingSourceGeraete.Current).Gruppe.Id = _lastGruppenKeyTmp;
                                ((DtoGeraete)bindingSourceGeraete.Current).Gruppe.Bezeichnung = gruppenBezeichnung;
                                _lastGruppenKeyTmp--;
                            }
                        }
                        break;
                }
    
            }
    
    

    If I enter a new value into the cell it is added to the DataMap and then displayed in the DropDown, but the value isn’t in the cell anymore. The cell is empty.



    How could I solve this problem?

    Thanks for your help

    Markus

  • Posted 23 December 2020, 9:04 am EST

    Hello Markus,

    There are few things not defined in the code snippet you shared. So, can you please share a stripped down application to show the problem?

    Thanks,

Need extra support?

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

Learn More

Forum Channels