Use this in youer event handler
var rows = GetDataGridRows(datagrid1);
foreach (DataGridRow r in rows)
{
foreach (DataGridColumn column in datagrid1.Columns)
{
if (column.GetCellContent(r) is TextBlock)
{
TextBlock cellContent = column.GetCellContent(r) as TextBlock;
MessageBox.Show(cellContent.Text);
}
}
}
Method to get the rows from datagrid
public IEnumerable<datagridrow> GetDataGridRows(DataGrid grid)
{
var itemsSource = grid.ItemsSource as IEnumerable;
if (null == itemsSource) yield return null;
foreach (var item in itemsSource)
{
var row = grid.ItemContainerGenerator.ContainerFromItem(item) as DataGridRow;
if (null != row) yield return row;
}
}
</datagridrow>