如何获取网格的可见行数?

How can I get the count of the visible rows of a grid?

我们在填充数据时遇到了这个障碍。假设我有 11 个测试,每个测试都有两个目标。该代码将数据填充到 WPF 中的 DevExpress 数据网格中。所以我有 11 个测试,但只有 5 个可见(我们滚动查看其余部分):

我正在尝试完成与此类似的事情:

    on first   VISIBLE row [Test1][Target1]
    on second  VISIBLE row [Test2][Target1]
    ..
    on last    VISIBLE row [Testn][Target1]

    next column

    on first   VISIBLE row [Test1][Target2]
    on second  VISIBLE row [Test2][Target2]
    ..
    on last    VISIBLE row [Testn][Target2]

当前代码是来自网格的事件处理程序,它可以工作,但有错误。它被调用的次数与可见行数(!!)一样多,但是我找不到如何控制它。该代码导致问题(有时复制数据,有时在列之间翻转数据)。评论是我真正想要的。一旦我到达最后一个 visible 行,我需要增加 unboudSampleDrawIndex 的目标索引。请帮助

private void testGrid_CustomUnboundColumnData(object sender, GridColumnDataEventArgs e)
{
    if (e.IsGetData)
    {
        Test currentTest = ((GalleryViewModel)DataContext).CurrentTests.ElementAtOrDefault(e.ListSourceRowIndex);
        unboundSampleDrawIndex = 0; // starts from target zero

        if (currentTest != null)
        {
            if ((int)e.Column.Tag < currentTest.Samples.Count && unboundSampleDrawIndex <= currentTest.Samples.Count - 1)
            {
                if (currentTest.IsReference)
                    e.Value = currentTest.Samples.ElementAt(unboundSampleDrawIndex).ABC; // here I am taking target 0 for the first column, until incremented
                else
                    e.Value = currentTest.Samples.ElementAt(unboundSampleDrawIndex).Delta; // here I am taking target 0 for the first column, until incremented
            }
            else
                e.Value = "";

            if (unboundSampleDrawIndex >= ??? ) //here I want to know it reached the last visible row
                unboundSampleDrawIndex++; // incremenet to populate next target
        }
    }
}

这解决了问题。通过为每一列生成一个标签,然后将其设置为目标向量中的索引。

    private void testGrid_CustomUnboundColumnData(object sender, GridColumnDataEventArgs e)
    {

        if (e.IsGetData)
        {
            Test currentTest = ((GalleryViewModel)DataContext).CurrentTests.ElementAtOrDefault(e.ListSourceRowIndex);

            if (currentTest != null)
            {
                if ((int)e.Column.Tag < currentTest.Samples.Count && unboundSampleDrawIndex <= currentTest.Samples.Count - 1)
                {
                    if (currentTest.IsReference)
                    {
                        e.Value = currentTest.Samples.ElementAt((int)e.Column.Tag).ABC;
                    }

                    else
                    {
                        e.Value = currentTest.Samples.ElementAt((int)e.Column.Tag).Delta;
                    }

                    unboundSampleDrawIndex++;
                }

                else
                {
                    e.Value = "";
                }

                if (unboundSampleDrawIndex >= currentTest.Samples.Count)
                {
                    unboundSampleDrawIndex = 0;
                }
            }
        }
    }