Wednesday, May 9, 2012

Access Datagrid Row in WPF through index


This is just a repost from this site: Accessing DataGridRow
Code:
  DataGridRow dgr = (DataGridRow)dataGrid1.ItemContainerGenerator.ContainerFromIndex(nRowIndex);  
  if (dgr == null) // row might be invisible (top / bottom). So, scroll into the view and get it  
  {  
    dataGrid1.UpdateLayout();  
    dataGrid1.ScrollIntoView(dataGrid1.Items[nRowIndex]);  
    dgr = (DataGridRow)dataGrid1.ItemContainerGenerator.ContainerFromIndex(nRowIndex);  
  } 
Thanks for the original contributor, this helped me a lot.

2 comments: