locked
WPF C# datagrid fix view row (fix scroll) RRS feed

  • Question

  • i am working on WPF datagrid and want to fix view after insert row at top, whenever row insert at top view scroll down by 1 row, i am using following code

    int i = 0; DataTable dt = null;

    private void UserControl_Loaded(object sender, RoutedEventArgs e) { dt = new DataTable(); dt.Columns.Add("Col1"); dt.Columns.Add("Col2"); DispatcherTimer dtimer = new DispatcherTimer(); dtimer.Tick += new EventHandler(dt_Tick); dtimer.Interval = new TimeSpan(0, 0, 1); dtimer.Start(); dataGrid1.DataContext = dt; } void dt_Tick(object sender, EventArgs e) { DataRow dr; dr = dt.NewRow(); dr["Col1"] = i; dr["Col2"] = i; dt.Rows.InsertAt(dr, 0); i++; }

    i tried to use dataGrid1.ScrollIntoView(dataGrid1.SelectedItem); but it still need selected item, and even it scroll down till last row in view

    I can manage to do the same in DataGridView of windows form in following way

    DataGridViewCell cell = dataGridView1.FirstDisplayedCell;
    dt.Rows.InsertAt(dr, 0);
    dataGridView1.FirstDisplayedCell = cell;

    looking for any similar ways to do this in WPF also

    Thanks.


    • Edited by suhas kalambe Sunday, May 19, 2013 5:49 AM
    • Moved by Just Karl Tuesday, May 21, 2013 2:19 PM Looking for the proper forum
    Sunday, May 19, 2013 5:49 AM

Answers

  • This forum is for discussions and questions regarding profiles and Microsoft's recognition system on the MSDN and TechNet sites. It is not for products/technologies.

    As it's off topic here, I am moving the question to the "Where is the forum for..." forum.

    However, I'd ask in the Windows Presentation Foundation (WPF) forum.

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    • Proposed as answer by Just Karl Thursday, May 23, 2013 8:38 PM
    • Marked as answer by Just Karl Monday, June 3, 2013 3:46 PM
    Tuesday, May 21, 2013 2:17 PM

All replies

  • This forum is for discussions and questions regarding profiles and Microsoft's recognition system on the MSDN and TechNet sites. It is not for products/technologies.

    As it's off topic here, I am moving the question to the "Where is the forum for..." forum.

    However, I'd ask in the Windows Presentation Foundation (WPF) forum.

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    • Proposed as answer by Just Karl Thursday, May 23, 2013 8:38 PM
    • Marked as answer by Just Karl Monday, June 3, 2013 3:46 PM
    Tuesday, May 21, 2013 2:17 PM
  • Thanks, i ll post into that topic also

    Tuesday, May 21, 2013 5:40 PM