in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Owner Draw and Sorting Tree View.

Last post 06-11-2008 3:57 PM by C1_GregL. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 09-21-2007 5:00 PM

    Owner Draw and Sorting Tree View.

    Hi Flexgrid Gurus,

      I'm trying to create a grid view where there are grouping (done after the data table is bound to the grid), and conditional formatting of data which are done in the Grid's Owner Draw Event.  I also need to allow user to Sort the column within the grouping (raw data from the data table sorted within the group, in the example below, it would be the Order Number). 

      However, when the user click on the column header to sort the data within the grouping, the grid's Tree nodes disapper completely(Node1 & Node 2 which groups by Company Name disappeared).  Is this expected?  

      Do i have to perform the subtotaling in the Owner Draw Cell event instead??  If so, could someone whip out a quick code for performing subtotalling in owner draw cell even?

    Thanks for any input in advance. 

     ( i have a simple sample ready that would demonstrate this, but I don't see where i can upload it.  So let me know and i'll email it to you or you can show me a place to upload it?)

    Dan

    ___________________________________ Example

    Node 1: Company A             |         Total Order: 3

    Data1:  Order 2

    Data2: Order 3

    Data3: Order 1

    Node 2: Company B              |       Total Order: 3

    Data4:  Order 1

    Data5: Order 3

    Data6: Order 2

  • 09-24-2007 11:18 PM In reply to

    Re: Owner Draw and Sorting Tree View.

    does anyone have a solutions to this? i have a similar problem, the subtotal tree disppearas after the column header is clicked for sorting

  • 09-28-2007 11:49 AM In reply to

    Re: Owner Draw and Sorting Tree View.

    I had included a sample code which will demonstrate this issue.  Could anyone give me some insight??

     (Run the sample, and click on the "Order Number" Column Header to sort within the group, and you'll see that all the grouping (subtotalling) will disappear). 

     Dan

  • 05-13-2008 3:34 AM In reply to

    Re: Owner Draw and Sorting Tree View.

    no response to this?
  • 06-11-2008 2:39 PM In reply to

    • MichaT
    • Not Ranked
    • Joined on 05-28-2008
    • Posts 1

    Re: Owner Draw and Sorting Tree View.

     

    I have the same problem and no solution yet. But I tried the following. I just added

     _flex.BeforeSort += new SortColEventHandler(Grid_BeforeSort);

    in my constructor. The "Grid_BeforeSort" looks like this:

    void Grid_BeforeSort(object sender, SortColEventArgs e)

    {

    // cancel built-in sorting

    e.Cancel = true;

     

    //sort within each node

    foreach (Row r in _flex.Rows)

    {

    if (r.IsNode)

    {

    int rowStart = 0;

    int rowCount = 0;

    CellRange range = r.Node.GetCellRange();

    rowStart = range.r1+1;

    rowCount = range.r2 - range.r1;

    // sort using custom comparer

    System.Collections.IComparer comp = new SortComparer(sender as C1FlexGrid, e);

    _all.Grid.Sort(rowStart, rowCount, comp);

    // update display and current sort order

    _flex.ShowSortAt(e.Order, e.Col);

    }

    }

    }

     The SortComparer Class looks like:

    class SortComparer : IComparer

    {

    // ** fields

    C1FlexGrid _flex;

    SortFlags _order;

    int _col;

    // ** ctor

    public SortComparer(ObservableC1FlexGrid flex, C1.Win.C1FlexGrid.SortColEventArgs e)

    {

    _flex = flex;

    _order = e.Order;

    _col = e.Col;

    }

    // ** IComparer

    int IComparer.Compare(object o1, object o2)

    {

    Row r1 = o1 as Row;

    Row r2 = o2 as Row;

    DataRowView sourceRow1 = r1.DataSource as DataRowView;

    DataRowView sourceRow2 = r2.DataSource as DataRowView;

    int cmp = 0;

    string s1 = null;if (sourceRow1 != null)

    {

    s1 = sourceRow1.Row.ItemArray[_col] as string;

    }

    string s2 = null;

    if (sourceRow2 != null)

    {

    s2 = sourceRow2.Row.ItemArray[_col] as string;

    }

    if (s1 == s2) cmp = 0;

    else if (s1 == null) cmp = +1;

    else if (s2 == null) cmp = -1;else cmp = string.Compare(s1, s2);

     

     

    if ((_order & SortFlags.Descending) != 0) cmp = -cmp;return cmp;

    }

    }

    What happens now is that all nodes are still available but the columns are not sorted. When I debug the sorting than I can see that the right column with the right data are compared but the result is not visible in the tree. Does anyone has an idea?

     

    Cheers,

    Michael

     

     

  • 06-11-2008 3:57 PM In reply to

    • C1_GregL
    • Top 10 Contributor
    • Joined on 06-11-2007
    • Pittsburgh PA
    • Posts 483

    Re: Owner Draw and Sorting Tree View.

    To solve the original issue you can recalculate the Subtotals in the AfterSort event.

    So perhaps you won't have to write your own sort?

     

    -Greg L

Page 1 of 1 (6 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.