且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

WPF C#datagrid修复视图行(修复滚动)

更新时间:2023-10-04 23:40:04





那么是什么阻止你插入对所选项目进行排序和/或使用创建的行来调用 ScrollIntoView



所以它应该足够了写:

Hi,

so what''s preventing you from making the inserted row either the selected item and/or using the created row to call ScrollIntoView?

So it should be enough to write:
void dt_Tick(object sender, EventArgs e)
{
   DataRow dr;
   dr = dt.NewRow();
   dr["Col1"] = i;
   dr["Col2"] = i; 
   dt.Rows.InsertAt(dr, 0);
   i++;

   // either do a scroll to inserted row
   dataGrid1.ScrollIntoView(dr);

   // or select item
   // dataGrid1.SelectedItem = dr;
   

   // and then scroll selected item into view
   // dataGrid1.ScrollIntoView(dataGrid1.SelectedItem);
}





希望这会有所帮助。



Hope this helps.