Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Exclude node from column sorting

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

Exclude node from column sorting
Link Posted: 11-Apr-2006 11:16
Hi,

I was wondering if it is possible to exclude some nodes from sorting. So that if I sort a column, those nodes stay fixed at the same position?

Thanks,

Tom
Link Posted: 11-Apr-2006 14:24
You can handle FlyGrid.ColumnSortOrderChanged event handler to move specific nodes to previous indexes, or use ColumnSortOrderChanging to implement custom sorting, in this case in the ColumnSortOrderChanging handler you should set sorted argument to True, this means that nodes sorted by custom comparer.
To manually sort nodes in this handler you can use following code:
[c#]
void ColumnSortOrderChangingHandler(object sender, Column column, SortOrder value, ref bool sorted)
{
  //sort nodes with custom IComparer implementor
  flyGrid.Rows.RootNode.Items.Sort(new MyCustomComparer(column, value));
  //custom sorting is succesfully finished - do not sort
  sorted = true;
}
Link Posted: 20-Apr-2006 11:00
hm, can you tell me why this doesn't work?

            if (column is GridHierachyColumn)
            {
                PositionMonitorGrid2 grid = sender as PositionMonitorGrid2;
                grid.Rows.Items.Sort(new NodeComparer(column, value));
                
                sorted = true;
                int index = accountNodeCache[\"TOTAL\"].Index;
                this.Rows.Items[index].Index = 0;
                grid.Rows.RefreshNodes();
            }


If I set the node back to index = 0, all the other nodes don't sort either?
Link Posted: 20-Apr-2006 12:15
//change index of node after refreshing nodes

if (column is GridHierachyColumn)
{
  PositionMonitorGrid2 grid = sender as PositionMonitorGrid2;
  grid.Rows.Items.Sort(new NodeComparer(column, value));
              
  sorted = true;  
  grid.Rows.RefreshNodes();
  int index = accountNodeCache[\"TOTAL\"].Index;
  this.Rows.Items[index].Index = 0;
}
Link Posted: 20-Apr-2006 12:21
doesn't work ... node is sorted and doesn't stay on top
Link Posted: 20-Apr-2006 12:53
I've hurried with answer
Try to create NodesComparer with top node in constructor and compare as top this node in Compare procedure.
Link Posted: 20-Apr-2006 21:12
sorry, I'm not quite sure how this should work? Can you post some quick sample code?

Thanks
Link Posted: 25-Apr-2006 21:34
Hi,

can you please follow up on this?

Thanks,

Tom
Link Posted: 27-Apr-2006 05:12
Sorry for delayed answer,
to solve this problem you should modify your custom IComparer to place specific nodes to top of the list.
Link Posted: 27-Apr-2006 05:14
Well, that's what I'm asking  how does the Compare method have to look like that the node is placed on top?