When the user clicks a column-header, I needed to sort not only by that column but by two columns (one of them is always the same) so i found this thread and tried it, but i'm getting a NullPointerException
This is my function:
private void DfgridDokumente_BeforeSortChange(object sender, BeforeSortChangeEventArgs e) {UltraGridColumn colOverdue = dfgridDokumente.DisplayLayout.Bands[0].Columns["colOverdue"];if (colOverdue != null) { e.SortedColumns.Insert(0, colOverdue, false); //<<-- here i'm getting a null pointer exception } }
When i'm in the debugger, colOverdue is set to the correct column, e.SoredColumns looks fine too
Any idea what's going wrong here?
dfboris said: colOverdue is set to the correct column, e.SoredColumns looks fine too
Well, if neither of those is null, then there's no way for me to guess what's happening there. Does the call stack of exception point to some other method or event handler?
Hi Boris,
I split this thread so we can keep this issue separate and create a case for you.
I tried this out using the Insert method as you described and I am seeing the same exception. So this is a bug in the grid. I think what's happening here is that the e.SortedColumns collection is a cloned collection of cloned columns. And you are inserted a column from the real grid (so it's not a clone) and this is causing the issue. When you Add a column via the key, it works okay, because you are not passing in a non-cloned column object and the grid is smart enough to create a clone. When you Add a column object, the grid detects this and clones it for you. But it seems that the Insert method fails to do this - probably just an oversight.
That being the case, you can work around this by using the Add method instead of insert:
private void ultraGrid1_BeforeSortChange(object sender, BeforeSortChangeEventArgs e) { var grid = (UltraGrid)sender; UltraGridColumn colOverdue = grid.DisplayLayout.Bands[0].Columns["Boolean 1"]; if (colOverdue != null) { if (e.SortedColumns.IndexOf(colOverdue) < 0) { List<UltraGridColumn> sortedColumns = new List<UltraGridColumn>(e.SortedColumns.Count + 1); sortedColumns.Add(colOverdue); foreach (UltraGridColumn sortedColumn in e.SortedColumns) { sortedColumns.Add(sortedColumn); } e.SortedColumns.Clear(); foreach (UltraGridColumn column in sortedColumns) e.SortedColumns.Add(column, false); } } }