简体   繁体   English

将 Syncfusion SfDataGrid 与列分组一起使用时,行索引不正确

[英]Incorrect RowIndex when using Syncfusion SfDataGrid with Column Grouping

Firstly I have to confirm that Syncfusion KB is so ugly...首先,我必须确认 Syncfusion KB 是如此丑陋......

I have a Syncfusion Datagrid bounded to a data source, and for some reason, I needed to group it on a specific column (Store Code).我有一个绑定到数据源的 Syncfusion Datagrid,出于某种原因,我需要将它分组到特定列(存储代码)。 在此处输入图片说明 Without grouping, everything seems to be OK, for example, row ID 17 is at index 1, and row ID 18 is at index 2 (one-based not zero-based).如果没有分组,一切似乎都没有问题,例如,行 ID 17 位于索引 1,行 ID 18 位于索引 2(从 1 开始,而不是从 0 开始)。 However, the problem is:然而,问题是:

When I use Grouping, like the image above, the row ID 17 is at index 2 (and should be 1), and the row with ID 23 is at index 10 (and should be 6).当我使用分组时,如上图所示,行 ID 17 位于索引 2(应为 1),ID 为 23 的行位于索引 10(应为 6)。

What happened is that all group headers (like 'StoreCode: XXXX - x Items') are calculated as rows, and subsequently increased the index by 4. This produces a big mistake when querying the underlaying data source because the indexes aren't the same.发生的事情是所有组头(如'StoreCode: XXXX - x Items')都按行计算,随后将索引增加了 4。这在查询底层数据源时会产生很大的错误,因为索引不相同. I found this link on Syncfusion and tried to apply the steps but with no luck.我在 Syncfusion 上找到了这个链接,并尝试应用这些步骤,但没有成功。

Code snippets:代码片段:

 private void DgQueuedOrders_CellButtonClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellButtonClickEventArgs e)
{

int CurrentRow = e.RowIndex;

DataTable gridDataTable = DgQueuedOrders.DataSource as DataTable;

int rowIndx = DgQueuedOrders.TableControl.ResolveToRecordIndex(CurrentRow);
}

From the provided details, we suspect that your requirement is to get the record corresponding the clicked button in both with and without grouping in SfDataGrid.根据提供的详细信息,我们怀疑您的要求是在 SfDataGrid 中有分组和没有分组的情况下获取与单击按钮对应的记录。 You can achieve this by using the following code example.您可以使用以下代码示例来实现此目的。

Code example :代码示例:

private void SfDataGrid1_CellButtonClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellButtonClickEventArgs e)
{
    int CurrentRow = e.RowIndex;

    DataTable gridDataTable = this.sfDataGrid1.DataSource as DataTable;

    int rowIndex = this.sfDataGrid1.TableControl.ResolveToRecordIndex(CurrentRow);

    if (this.sfDataGrid1.GroupColumnDescriptions.Count > 1)
    {
        var record = sfDataGrid1.View.TopLevelGroup.DisplayElements[rowIndex];
        if (!record.IsRecords)
            return;
        var row = (record as RecordEntry).Data;
    }
    else
    {
        var record = sfDataGrid1.View.Records[rowIndex];
        if (!record.IsRecords)
            return;
        var row = (record as RecordEntry).Data;
    }
}

Regards, Mohanram A.问候, Mohanram A.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM