We have this obstacle in populating data. Let's say I have 11 tests and every test has two targets. The code populates data into a DevExpress data grid in WPF . So I have 11 tests but only 5 are visible (we scroll to see the rest):
I am trying to accomplish something similar to this:
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]
The current code is an event handler from the grid and it works but with erros. It gets called exactly as much as visible rows count (!!) however I couldn't find how to control that. The code is causing problems (duplicating data sometimes and flipping data between columns sometimes). Commented is what I really want. I need to incremenet target index which is unboudSampleDrawIndex
once I reach the last visible row. Please help
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
}
}
}
This fixed the issue. By generating a tag for every column and then setting it as the index in the target vectors.
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;
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.