我们在填充数据时遇到了这个障碍。让我们说我有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]
当前代码是来自网格的事件处理程序,但它可以使用错误。它被称为与可见行数(!!)完全相同但是我无法找到如何控制它。代码导致问题(有时重复数据并有时在列之间翻转数据)。评论是我真正想要的。一旦到达最后一个可见行,我需要递增目标索引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
}
}
}
答案 0 :(得分:0)
这解决了这个问题。通过为每列生成标记,然后将其设置为目标向量中的索引。
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;
}
}
}
}