Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
Setting XamDataGrid.DataSource every several seconds causes issues
posted

My application acts like a monitor on a database.
Every 5 seconds I'm retrieving the data and setting it to the grid.DataSource.

public void SetDataSource(object dataSource)
{
    //Before the data changes we save the selected DataId and the scroller ofset,
    // and if we can, resetting it after so the user wont fill the cange.

    double scrollerVerticalOffset = this.grdData.ScrollInfo.VerticalOffset;
    int selectedDataId = 0;
    this.TryGetSelectedDataId(out selectedDataId);

    this.grdData.DataSource = (IEnumerable)dataSource;

    Record selectedDataRecord = null;
    if (this.TryGetDataRecord(selectedDataId, out selectedDataRecord))
    {
        this.grdData.ActiveRecord = selectedDataRecord;
    }
    this.grdData.ScrollInfo.SetVerticalOffset(scrollerVerticalOffset);
}

I have encountered these 2 issues which I need help for,
Both happens even when the data in the database isn't changed at all :

1. If no row was selected before the update, the ScrollInfo.SetVerticalOffset sets the offset to the offset before the change like it suppose to, but the grid automaticly scrolls to the top of the grid.
If a row was selected before the update, the grid remains scrolled to the same offset it was before, just like I want it to do.

2. If I do select a row and scrolls down, the application looks ok and nothing flickers,
Except when the mouse hovers above the grid.
The row below the mouse changes color like it suppose to, but with every grid.DataSource set, the row's unique color jumps to a different row and back.

Can someone help me with these issues ?

Thanks
Eyal