How to embed C1ExpressionEditor into C1DataGrid or C1FlexGrid columns?

Posted by: ydolapchiev on 15 October 2020, 7:36 pm EST

  • Posted 15 October 2020, 7:36 pm EST

    I am very new to this tool and I cannot find any materials online to guide me on how to bind a C1ExpressionEditor to a column of either C1DataGrid or C1FlexGrid. I need to make it so the user can change the expressions in some of the columns to fit their own requirements. I want to add the function icon on the side of the column and when the user clicks it, an expression editor is opened and the user can modify the expression of the column.
    All the tutorials and guides I have found on the topic are on other apps and do not seem to work in WPF.
  • Replied 18 October 2020, 10:06 pm EST

    Hello Yordan,

    To integrate C1ExpressionEditor with C1FlexGrid, you can refer the following documentation:
    However, if you want to integrate the ExpressionEditor to a column in grid the way you wanted, please refer attached application. In the application the editor is integrated to the last column in view and pops up upon entering the edit mode.

  • Replied 19 October 2020, 2:03 am EST

    Thank you for the fast response. However, I expected there to be a simpler way to do this based on the images in the wpf expression editor web page. Should I take it that there is no simple way to implement this functionality without writing it yourself?
    Also, whenever I sort the grid by any of the columns, the results in the expression column become completely wrong. I have not changed anything in the code you have provided.
    Lastly, will it be possible to show me how to embed the expression editor into a datagrid since I will not be able to use a flexgrid for my task?
  • Replied 19 October 2020, 10:45 pm EST


    Do you mean the images shown in the following page:
    This page is common to WinForms and XAML technologies, so the first few images are specific to WinForms, where it is relatively easier to integrate editor to grid.

    >Also, whenever I sort the grid by any of the columns, the results in the expression column become completely wrong.
    I am not able to observe any problem in column values calculated via expression, even after sorting multiple columns. Can you please share a video? Also, please ensure that you are using the latest version of ComponentOne controls.

    For integrating C1ExpressionEditor to DataGrid, please refer:

  • Replied 20 October 2020, 5:17 pm EST


    I cannot send you a recording of the bug but I can tell you how to recreate it. You simply have to first sort the grid by any column and then when you try to apply the expression, you will notice that the results are ordered as if the grid were never sorted. This bug also occurs in the official wpf expression editor example application that came with the installation file. I believe it is because after sorting, the indexes of the items are not updated which causes the expression editor to return the wrong values for the fields after they have been sorted.

  • Replied 21 October 2020, 5:19 pm EST


    I got it now and can see the problem. I am discussing it with the developers [ID-26632] and will get back to you as there is an update.
    Thank you for reporting it.

  • Marked as Answer

    Replied 31 October 2020, 8:04 am EST


    This problem is caused by sorting. After C1FlexGrid is sorted, the index of rows in C1FlexGrid (view index) is not the same as the index from initial ItemsSource (model index) anymore.
    The ExpressionEditor works with model index, meaning its value is calculated from model index. So, the problem with the above sample was when we update the evaluated value to C1FlexGrid, we were not updating to the correct model index row.
    To resolve this, please modify the SetValue method in FlexGridEE class to the following:
    public void SetCellValue(int row, string colName, object value)
    var colView = CollectionView as System.Windows.Data.ListCollectionView; //The sorted collection
    var sourceCol = colView.SourceCollection as System.Collections.IList; //The original collection
    //Get the real model index
    var realRowIndex = colView.IndexOf(sourceCol[row]);
    this[realRowIndex, colName] = value;

    // this[GetRowIndex(row), colName] = value;
Need extra support?

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

Learn More

Forum Channels