C1FlexGrid Edit Behavior

Originally Posted 28 August 2017, 10:58 am EST

  • Originally Posted 28 August 2017, 10:58 am EST

    I would the the cells of FlexGrid to act like a text box when editing. A single click on the cell should enter edit mode and position the cursor at the end of the text and flash. Is that possible?
  • Marked as Answer

    Reply

    Hi,
    Please try to use CellEditEnded event instead of BeginningEdit as:

    private void Flexgrid_CellEditEnded(object sender, C1.WPF.FlexGrid.CellEditEventArgs e)
    {
    IEditableCollectionView EditableCollectionView = flexgrid.CollectionView as IEditableCollectionView;
    if (EditableCollectionView != null && EditableCollectionView.CurrentEditItem != null)
    {
    EditableCollectionView.CommitEdit();
    }
    else
    {
    EditableCollectionView.CommitNew();
    }
    ICollectionView CollectionView = CollectionViewSource.GetDefaultView(flexgrid.ItemsSource);
    using (CollectionView.DeferRefresh())
    {
    CollectionView.SortDescriptions.Clear();
    CollectionView.SortDescriptions.Add(new SortDescription("Age", ListSortDirection.Ascending));
    }
    }

    Hope, it will solve your issue.

    Thanks,
    Singh Sonu
  • Reply

    Hi Rich,

    Please use the following code to accomplish your requirements:

    private void TestGrid_PrepareCellForEdit(object sender, C1.WPF.FlexGrid.CellEditEventArgs e)
    {
    var editor = (e.Editor as Border).Child as C1.WPF.FlexGrid.C1FlexComboBox;
    if (editor != null)
    {
    editor.Loaded += (s, e1) =>
    {
    editor.SelectionStart = editor.Text.Length + 1;
    };
    }
    }

    private void TestGrid_SelectionChanged(object sender, C1.WPF.FlexGrid.CellRangeEventArgs e)
    {
    TestGrid.StartEditing(true);
    }



    Thanks,
    Pragati
  • Reply

    Thank you for the reply.
    I have a related question: How do you edit a sorted grid without having the rows jump as you edit them? I was adding a new SortDescription to the CollectionView during the edit but it prevents the PrepairCellForEdit from firing. The code below is called from BeginningEdit.


    using (CollectionView.DeferRefresh())
    {
    CollectionView.SortDescriptions.Clear();
    CollectionView.SortDescriptions.Add(new SortDescription("SuspendedSortOrder", ListSortDirection.Ascending));
    }
  • Reply

    I was able to get it working by using the PrepareCellForEdit event instead of the CellEditEnded.

    Can you make an example application that shows how to suspend and resume sorting when editing is being done? It should retain the column that was being sorted before the edit began and resume sorting on the same column after editing is complete.
  • Reply

    Hi,
    Please note, If you edit a column that already sorted then it sorted the data again after editing is finished. This is the design behavior of the C1FlexGrid.

    Hope, it clarifies for you.

    If you want to sort the column that is not sorted currently. You can use the CellEditEnded event for the same and use the below steps:
    1) Get the current column name:
    string columnName = flexgrid.Columns[e.Column].ColumnName;

    2) now add a SortDescription using the same column name:
    CollectionView.SortDescriptions.Clear();
    CollectionView.SortDescriptions.Add(new SortDescription(columnName, ListSortDirection.Ascending));


    See the previous code implementation.
    Hope, it will work for you.

    Thanks,
    Singh Sonu
  • Reply

    From response above:
    "Please note, If you edit a column that already sorted then it sorted the data again after editing is finished. This is the design behavior of the C1FlexGrid."

    That is a big problem. As soon as a user makes a change to a cell in a sorted column it jumps to a new location and the user has to scroll around and find it. Each time the user makes a change he/she has to go looking for it. That is not practical.

    What I would like from you is a simple example that shows how to avoid this. Sorting should stop as soon as the user begins the first edit and resume after after a Save event (such as clicking a button). I could not find this in your example applications.
  • Reply

    Hi,
    you need to implement your own custom sorting using the IComparer. Please find the attached sample implementing your scenario an let me know if it works for you.

    Hope it helps.

    Thanks,
    2017/09/WPF_C1FlexGrid_SortingCustom.zip
Need extra support?

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

Learn More

Forum Channels