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
220
Sorting a special way only when user clicks first header.
posted

Hello. I currently have a custom sort setup.

 

            ultraGridDaySheet.DisplayLayout.Bands[m_DaySheetDataSet.DaySheet.TableName].Columns[m_DaySheetDataSet.DaySheet.TimeColumn.ColumnName].SortIndicator = SortIndicator.Ascending;
            ultraGridDaySheet.DisplayLayout.Bands[m_DaySheetDataSet.DaySheet.TableName].Columns[m_DaySheetDataSet.DaySheet.ApptStateDispCharColumn.ColumnName].SortComparer = new MySortComparer();
            ultraGridDaySheet.DisplayLayout.Bands[m_DaySheetDataSet.DaySheet.TableName].SortedColumns.Add(ultraGridDaySheet.DisplayLayout.Bands[m_DaySheetDataSet.DaySheet.TableName].Columns[m_DaySheetDataSet.DaySheet.ApptStateDispCharColumn.ColumnName], false);
            ultraGridDaySheet.DisplayLayout.Bands[m_DaySheetDataSet.DaySheet.TableName].Columns[m_DaySheetDataSet.DaySheet.ArrivalTimeColumn.ColumnName].SortIndicator = SortIndicator.Ascending;

 

 

What I'd like to accomplish is when the user clicks the first header of columns, I'd like it to be sorted with that code. How would I go about doing this?

 

I've tried the following:

 

        private void ultraGridDaySheet_AfterSortChange(object sender, BandEventArgs e)
        {
            ultraGridDaySheet.DisplayLayout.Bands[m_DaySheetDataSet.DaySheet.TableName].Columns[m_DaySheetDataSet.DaySheet.TimeColumn.ColumnName].SortIndicator = SortIndicator.Ascending;
            ultraGridDaySheet.DisplayLayout.Bands[m_DaySheetDataSet.DaySheet.TableName].Columns[m_DaySheetDataSet.DaySheet.ApptStateDispCharColumn.ColumnName].SortComparer = new MySortComparer();
            ultraGridDaySheet.DisplayLayout.Bands[m_DaySheetDataSet.DaySheet.TableName].SortedColumns.Add(ultraGridDaySheet.DisplayLayout.Bands[m_DaySheetDataSet.DaySheet.TableName].Columns[m_DaySheetDataSet.DaySheet.ApptStateDispCharColumn.ColumnName], false);
            ultraGridDaySheet.DisplayLayout.Bands[m_DaySheetDataSet.DaySheet.TableName].Columns[m_DaySheetDataSet.DaySheet.ArrivalTimeColumn.ColumnName].SortIndicator = SortIndicator.Ascending;
        }

 

But I get an error and crashes when this occurs.

Parents
  • 469350
    Offline posted

    What's the error?

    I don't think you can change the sorting in the AfterSortChange. Doing so will either not work or it will cause an infinite loop, since changing the sorting causes the event to fire again, which changes the sorting, which fires the event again, etc.

    You could use a flag to prevent recursion or use the EventManager to disable the event while you are in it. But I think it's probably easier to use BeforeSortChange, instead and modify the new sort information passed in to the event args.

Reply Children