Hello All
I wanted to find the datagrid column header when a cell is clicked.. i used the following code
private void grid1_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
DependencyObject dep = (DependencyObject)e.OriginalSource;
while ((dep != null) &&
!(dep is DataGridColumnHeader))
{
dep = VisualTreeHelper.GetParent(dep);
}
if (dep == null)
return;
if (dep is DataGridColumnHeader)
{
DataGridColumnHeader columnHeader = dep as DataGridColumnHeader;
if (columnHeader.ToString() == "Adv Comments")
{
MessageBox.Show(columnHeader.Column.Header.ToString());
}
}
if (dep is DataGridCell)
{
DataGridCell cell = dep as DataGridCell;
}
}
But the column header is not a direct parent for the datagrid cell so its not able to find it. is there anyother way out??