Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Unable to scroll to position in datagrid after datacontext refesh

$
0
0

When I refresh the datacontext I cannot get the scrollviewer to scroll back to its original position. For example, I scroll down to a row, double click to open a window and modify the content which updates a database, refresh the datacontext and then call scrollViewer.ScrollToVerticalOffset(offset). 

        void dg_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            scrollViewer = GetVisualChild<ScrollViewer>(dg);
            if (scrollViewer != null)
            {
                offset = scrollViewer.VerticalOffset;
            }

            int x = dg.SelectedIndex;
            int rowIndex = dg.SelectedIndex;
            int rowCount = dg.Items.Count - 1;
            try
            {
                CalendarItem currentCell = (CalendarItem)dg.CurrentCell.Item;

                if (currentCell != null)
                {
                    ModifyItem newModifyItemWindow = new ModifyItem(currentCell.ID, false);

                   bool?  DialogResult = newModifyItemWindow.ShowDialog();
                    if(DialogResult == true)
                    {
                        RefreshCalendar();
                    }
                }
            }
            catch (Exception)
            {
                return;
            }

            scrollViewer.ScrollToVerticalOffset(offset);
           // not working
        }

However, once the window has closed I can click on a button and the the datagrid scrolls correctly. I cannot find a way to make the scroll happen automatically.


:-( Still trying to program


Viewing all articles
Browse latest Browse all 18858

Trending Articles