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

WPF C# datagrid fix view row (fix scroll)

$
0
0

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;

privatevoidUserControl_Loaded(object sender,RoutedEventArgs e){ dt =newDataTable(); dt.Columns.Add("Col1"); dt.Columns.Add("Col2");DispatcherTimer dtimer =newDispatcherTimer(); dtimer.Tick+=newEventHandler(dt_Tick); dtimer.Interval=newTimeSpan(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.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>