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: 27-Apr-2006 06:28
Here is modified code:
[c#]
public class NodesComparer : IComparer
{
  private SortOrder order;
  private Column col;
  private NodeBase topNode;
  public NodesComparer(Column col, SortOrder order, NodeBase topNode)
  {
    this.topNode = topNode;
    this.col = col;
    this.order = order;
  }
  #region IComparer Members
  public int Compare(object x, object y)
  {        
    //keep top node on the top
    if (x == y) return 0;
    if (x == topNode) return -1;
    if (y == topNode) return 1;
    
    Node xnode = x as Node;
    Node ynode = y as Node;
    
    int result = 0;
    object xobj = xnode.GetCellValue(col);
    object yobj = ynode.GetCellValue(col);
    IComparable xvalue = xobj as IComparable;
    IComparable yvalue = yobj as IComparable;
    
    if (order == SortOrder.Ascending)
    {
      result = xvalue == null ? yvalue == null ? 0 : -1 : xvalue.CompareTo(yvalue);
    }
    else if (order == SortOrder.Descending)
    {
      result = yvalue == null ? xvalue == null ? 0 : -1 : yvalue.CompareTo(xvalue);
    }
    return result;
  }
  #endregion
}
Link Posted: 27-Apr-2006 09:02
perfect, that works, thx!
Link Posted: 27-Apr-2006 09:59
hm, not sure if this is a bug or expected behavior:

I have a column that is editable and sorted. Now I change the cell value by typing somthing in there. In CellValueChanged method I'm adding a row with this.Row.Items.Add(newNode);
Now, the node that I typed something into gets sorted to somewhere at the top, however the new node that I just added appears just below it. Shouldn't it appear as the last row of the grid? If this is normal behavior, how can I make sure that the new node gets added to the bottom?
Link Posted: 27-Apr-2006 10:27
May be it would more better if you focus new node after addition?
Link Posted: 27-Apr-2006 11:06
sorry, but I don't follow? What does focusing the node change?
I want to add a new node as soon as there is something entered in the existing node but the new node should always be on bottom
Link Posted: 03-May-2006 20:57
can you please follow up on this as well?

thanks
Link Posted: 11-May-2006 06:38
If node has some data this node will sorted.
You can mark this node as [new node] and exclude from sorting by method discussioned earlier.
Link Posted: 12-May-2006 10:59
in case you mean like this:

                            this.Rows.Items.Add(newNode);
                            this.FocusNode(this.ActivePort, newNode, ColumnCache[\"symbol\"], false);
                            this.Rows.Items.Sort(new NodeComparerWithBottomNode(this.Columns.Items[\"symbol\"], this.Columns.Items[\"symbol\"].SortOrder,  newNode));


... this doesn't work.

It works as long as the sort order on the column is not changed. But when the user changes the sort order, this doesn't work anymore and the newly added node ends up somewhere in the middle
Link Posted: 13-May-2006 09:46
The nearest FlyGrid.Net update will contain possibility to override default comparer.
You can override FlyGrid.GetComparer(Rows rows, Column[] sortColumns) method to use your own comparer with this update.