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?
To ensure that this issue will receive attention, I have logged this behavior in our internal tracking system with a Development ID of 220099. The next step will be for a developer to review my investigation and confirm my findings or to offer a fix, or other resolution.I will leave this case open and update you with any new information after the review. You can also continue to send updates to this case at any time.You can view the status of the development issue connected to this case by selecting the "Development Issues" tab when viewing this case on the web site. Please let me know if you need more information.
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); } } }
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?