Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
295
Right click on header to select column
posted

We're trying to figure out which column was selected when the user right clicks.

We tried the following:

        private void _xamDataGrid_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            DataRecordPresenter rec = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(DataRecordPresenter), false) as DataRecordPresenter;
            if (rec != null)
            {
                if(rec.Record.RecordType.ToString() == "HeaderRecord")
                {
			// get name of column...
                }
            }
        }
 
But can't seem to get the column name.  Can you help please?
Thanks,
Jon
 
  • 35319
    posted

    Hello Jon,

     

    I am just checking if you require any further assistance on the matter.

  • 35319
    posted

    Hello,

     

    I have been looking into your question and I achieved the functionality that you are looking for by programmatically sorting :

     

    http://help.infragistics.com/Help/NetAdvantage/WPF/2012.1/CLR4.0/html/xamDataPresenter_Programmatically_Sort_and_Group_Fields.html

     

    You can try the following code :

     

         private void xamDataPresenter1_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)

            {

                var labelPresenter = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(LabelPresenter), true);

     

                FieldSortDescription desSort = new FieldSortDescription();

                desSort.Direction = System.ComponentModel.ListSortDirection.Descending;

     

                FieldSortDescription ascSort = new FieldSortDescription();

                ascSort.Direction = System.ComponentModel.ListSortDirection.Ascending;

                string clickedFieldName = ((DataItemPresenter)labelPresenter).Field.Name;

                ascSort.FieldName = desSort.FieldName = clickedFieldName;

     

                if (((DataItemPresenter)labelPresenter).Field.SortStatus == Infragistics.Windows.Controls.SortStatus.Descending)

                {

                    this.xamDataGrid1.FieldLayouts[0].SortedFields.Clear();

                    xamDataGrid1.FieldLayouts[0].SortedFields.Add(ascSort);

                }

                else if (((DataItemPresenter)labelPresenter).Field.SortStatus == Infragistics.Windows.Controls.SortStatus.Ascending)

                {

                    this.xamDataGrid1.FieldLayouts[0].SortedFields.Clear();

                    xamDataGrid1.FieldLayouts[0].SortedFields.Add(desSort);

                }

                else

                {

                    this.xamDataGrid1.FieldLayouts[0].SortedFields.Clear();

                    xamDataGrid1.FieldLayouts[0].SortedFields.Add(ascSort);

                }

            }

     

    Please let me know if you need any further assistance on this matter.