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
735
WinGrid custom column sorting
posted

Hi, I have a grid with custom column comparer class for each column to do custom sorting. Right now, I can do  one column sorting, or multiple column sorting by holding shift key and select multiple columns. However, we  want to always add the first column for sort. User wants to just click one of the other column to perform two columns sorting without holding the shift key. In other word, we want to add the first column to sorting columns as the first sort no matter which column user clicks.

One possible way to do that, I think, is to disable the column click sorting on column header, catch the header click event, then programatically add the first column and the column user click to sorted column list.

Is there any easy way to do that?

Thanks,
Zongwen

Parents
No Data
Reply
  • 660
    posted

    Hm. I hoped you would told me, that i'm using the wrong way to get the column :) 

    OK, more details:

    - if i'm using the .add("key-of-column"...) (instead of .insert(column-object) i don't get the error - but not the correct result as the added columns needs to be first column for the sorting

    - using the .insert(0, ...) doesn't give an error if the e.SortedColumns List is empty

    - But if i click a column header, the event is triggert with the clicked column in the e.SortedColumns. The List contains 1 element. Then, when trying to .insert(0...) i'm getting this error.

    The Error:

    System.NullReferenceException occurred
    HResult=-2147467261
    Message=Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
    Source=Infragistics4.Win.UltraWinGrid.v16.1
    StackTrace:
    bei Infragistics.Win.UltraWinGrid.SortedColumnsCollection.Insert(Int32 insertIndex, UltraGridColumn column, Boolean groupBy)
    bei ...ucDokumenteGridView.DfgridDokumente_BeforeSortChange(Object sender, BeforeSortChangeEventArgs e) in ...ucDokumenteGridView.cs:Zeile 1290.
    InnerException:

    Screenshots to show you, that e.SortedColumns looks OK and the colOverdue is filled too:

    SortedColumns is set

    colOverdue is set too

    Again, this is how my function looks right now (i've added a check to avoid adding the column a second time)

    private void DfgridDokumente_BeforeSortChange(object sender, BeforeSortChangeEventArgs e)
    {
    UltraGridColumn colOverdue = dfgridDokumente.DisplayLayout.Bands[0].Columns["colOverdue"];

    if (colOverdue != null)
    {
    if (e.SortedColumns.IndexOf("colOverdue") < 0)
    {
    e.SortedColumns.Insert(0, colOverdue, false);
    //e.SortedColumns.Add("colOverdue", true, false);
    }
    }
    }

Children