C1DataGrid FilterRow increases RowIndex

Posted by: gregor.sch on 25 July 2018, 7:41 am EST

    • Post Options:
    • Link

    Posted 25 July 2018, 7:41 am EST

    When I insert a FilterRow in the TopRows section of a C1DataGrid, the indexing gets messed up (example: when calling the SelectedIndex method, the item one row below is selected, instead of the item in the selected row).

    How can I fix this? I made a custom C1DataGrid control and am inserting the FilterRow programmatically. Ideally, I would like to resolve the issue in the same method…

    Thanks, G

  • Posted 26 July 2018, 5:46 am EST

    Hi,

    I can observe that adding FilterRow in TopRows collection increases DataGrid.Rows.Count. However, I doubt whether its possible to prevent counting FilterRow in grid’s Rows collection. One way you can circumvent this behavior is subtract the TopRows count while calculating the row index, as follows:

            private void Grid_LoadedRowPresenter(object sender, C1.WPF.DataGrid.DataGridRowEventArgs e)
            {
                e.Row.Presenter.PreviewMouseLeftButtonUp += Presenter_PreviewMouseLeftButtonUp;
            }
            private void Presenter_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
            {
               [b] int rowIndex = ((C1.WPF.DataGrid.DataGridRowPresenter)sender).Row.Index - grid.TopRows.Count;[/b]
                MessageBox.Show($"{rowIndex}");
                e.Handled = true;
            }
    
    ```Would this workaround be good enough for you?
    Let me know, if you need any help further.
    
    Thanks,
    Ruchir
  • Posted 27 July 2018, 3:04 am EST

    Hi Ruchir,

    I was hoping for a solution without code modifications, since the app includes quite a few C1DataGrid instances and the RowIndex are accessed through various methods. I guess it’s a limitation we have to live with and use the workaround from code-behind.

    Best regards, G

  • Posted 30 July 2018, 4:22 am EST

    Hello,

    Circumventing this behavior without using code is not possible. Therefore, yes, to workaround this, you will have to use the above workaround.

    Apologies for the inconvenience caused.

    Regards,

    Ruchir

Need extra support?

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

Learn More

Forum Channels