Hi,
i am trying to change the column header text on right click. How do i get the Current column on the grid on mouse right click event.
You can try the following snippet:
... this.XGrid.MouseRightButtonUp += new System.Windows.Input.MouseButtonEventHandler(XGrid_MouseRightButtonUp); this.XGrid.MouseRightButtonDown +=new System.Windows.Input.MouseButtonEventHandler(XGrid_MouseRightButtonDown); ... private void XGrid_MouseRightButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { System.Windows.Point p = e.GetPosition(Application.Current.RootVisual); IEnumerable<HeaderCellControl> elements = VisualTreeHelper.FindElementsInHostCoordinates(p, Application.Current.RootVisual).OfType<HeaderCellControl>(); HeaderCellControl headerCellControl = elements.FirstOrDefault(); if (headerCellControl != null) { headerCellControl.Cell.Column.HeaderText = "Right clicked!"; e.Handled = true; } } private void XGrid_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { e.Handled = true; } ...
HTH
Thanks. It worked well for me.