Home Forums WinForms controls Xceed Grid for WinForms SummaryCell or ValueCell – Need text and calc in cell

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16517 |

    Hi

    I’m calculating avg,sum etc using summarycells (statfunction) in summaryrow and ad as footer row for a group.

    Issue – I want text in many of the none calculated cells however, this seems not possible. Tried setting cell Value & NullText.

    With a valuecell in a valuerow as a footer, I simply set the cell value but have to go about coding avg,sum etc – MISSION.

    Does this mean I cannot use summaryrow but must use valuerow – This massively limits the use of summaryrow. If I don’t have a choice how do I go about doing this most efficiently ?

     

     

     

    Imported from legacy forums. Posted by Comodo (had 2984 views)

    User (Old forums)
    Member
    Post count: 23064

    Use the TitlePosition and TitleFormat on SummaryCell to edit text and decide in which cell the text will be displayed (in the left or in the right cell of the calculated result cell).

    Here is another post giving more details :

    http://xceed.com/CS/forums/thread/1910.aspx

    We also have a topic in our help documentation :

    http://doc.xceedsoft.com/products/XceedGrid/How_to_display_running_sums.html

    Imported from legacy forums. Posted by André (had 448 views)

    User (Old forums)
    Member
    Post count: 23064

    That only allows me to write 1 line of text. I have many “constant cells” and want to write to them.

    Simple example to make things clear

    Orignal table

    Product Type Price Country 

    Volvo Sedan $12 TW

    BMX Sedan $20 TW

    BMW 4×4  $30 XX

    BMW 4×4  $10 YY

    New table (With text & Calculated cells)

    Group1 Sedan $32 TW    (Group1, Sedan and TW are text in cells and $32 is calculated)

    Group2 4×4     $30 XX

    Group3 4X4    $10 YY

     

    Thanks

     

    Imported from legacy forums. Posted by Comodo (had 515 views)

    User (Old forums)
    Member
    Post count: 23064

    This is not possible with the SummaryRow.  What you can do is, as you first suggested, to use a ValueRow do display the text and statistics you want, but still use the SummaryRow to feed the data in the ValueRow.   Simply hide the SummaryRow, so it does not show up in the grid.  Note that the statistics in the SummaryRow are calculated very late in the process, so the only way to get the updated value once a cell has changed in the grid is to use the Application.Idle event.

    e.g. :

    //assuming a SummaryRow and ValueRow have been added in the FixedFooterRows in the designer 

    private void Form1_Load( object sender, EventArgs e )

    {

        gridControl1.FixedFooterRows[ 0 ].Visible =

    false;

        dataRowTemplate1.Cells[

    “Price” ].ValueChanged += new EventHandler( Form1_ValueChanged );

    }

    void Form1_ValueChanged( object sender, EventArgs e )

    {

        Application.Idle += new EventHandler( Application_Idle );

    }

    void Application_Idle( object sender, EventArgs e )

    {

        Application.Idle -= new EventHandler( Application_Idle );

        SummaryRow sumRow = gridControl1.FixedFooterRows[ 0 ] as SummaryRow;

        ValueRow valueRow = gridControl1.FixedFooterRows[ 1 ] as ValueRow;

        if( sumRow != null && valueRow != null )

        {

            valueRow.Cells[

    “Price” ].Value = sumRow.Cells[ “Price” ].Value;

        }

    }

     

    Imported from legacy forums. Posted by André (had 507 views)

    User (Old forums)
    Member
    Post count: 23064

    OK nearly there – just check my questions again (Allowing summary cells to have plain text would be soooo nice)

    My problem is that I’m not using FixedFooterRows, rather many Group.FooterRows and have no idea where I am in Application_Idle  ?

    Perhaps I’m missing something … but how do I find the right summary and value row in Application_Idle

     Is there no valuechanged event (or similar) that i can use for the summarycell – Does not seem to fire

    Can I not override the calculated result for a summary cell …

    Imported from legacy forums. Posted by Comodo (had 741 views)

    User (Old forums)
    Member
    Post count: 23064

    You can simply keep a reference to the Group in the ValueChanged event, and use it in the Idle event handler.

    e.g.:

    private Group group;

    void Form1_ValueChanged( object sender, EventArgs e )

    {

        //Get the group of the DataRow that was just updated

        DataCell cell = sender as DataCell;

        if( cell != null )

        {

            group = cell.ParentRow.ParentGroup

    as Group;

        }

        Application.Idle += new EventHandler( Application_Idle );

    }

     

    //Do the update to the ValueRow

    void Application_Idle( object sender, EventArgs e )

    {

        Application.Idle -= new EventHandler( Application_Idle );

        if( group != null )

        {

            SummaryRow sumRow = group.FooterRows[ 0 ] as SummaryRow;

            ValueRow valueRow = group.FooterRows[ 1 ] as ValueRow;

            if( sumRow != null && valueRow != null )

            {

                valueRow.Cells[

    “SupplierID” ].Value = sumRow.Cells[ “SupplierID” ].Value;

            }

        }

    }

     

    Imported from legacy forums. Posted by André (had 478 views)

    User (Old forums)
    Member
    Post count: 23064

    I manually create 3 groups create the summary and value rows when pressing on a button for the last group.

    Populating the valuerow with summaryrow data works about 80% of the time but it seems as if the first couple of rows don’t always get populated with data. I can press on my button several times and see some data, then not, then again etc etc. There is no clear sequence of what rows don’t get populated ?? It seems as if the data simply isn’t drawn since data even sometimes dissapears when I scroll up/down – This includes fixed text that I set in a cell in my valuerow only once. (Grid version 3.7)

    I also tried creating a list of groups in valuechanged to ensure i don’t at some point override the group used in application_idle, that i run through in application_idle – still no use (This will obviously not help my fixed text in the valuecell that is set only once and also starts to randomly dissapear)

     Soooo what now ?

    How about simply allowing text in a summaryrow ?

    Imported from legacy forums. Posted by Comodo (had 691 views)

    User (Old forums)
    Member
    Post count: 23064

    *** Set

    UIVirtualizationMode = UIVirtualizationMode.None

     Now none of the “calculated” cells update but my fixed text cells are always there. It seems as if repainting / virtualization goes funny and doesn’t always draw the data in cells.

    *** Also tried to hide the summary rows from whcih I derive my new valuerows data – Once I do this all my data comming from the summaryrow will never display.

    Imported from legacy forums. Posted by Comodo (had 747 views)

    User (Old forums)
    Member
    Post count: 23064

    On my side, if I set UIVirtualizationMode to None, it works fine, that is, all values update correctly in the ValueRow, except that I need to also have a one time Application.Idle event, since the SummaryRow values are calculated so late that it is the only way to get the SummaryRow to update the ValueRow.

    e.g. :

    private void Form1_Load( object sender, EventArgs e )

    {

        gridControl1.UIVirtualizationMode =

    UIVirtualizationMode.None;

        Application.Idle += new EventHandler( First_Application_Idle );

    }

    //This runs only once, after the grid as loaded

    void First_Application_Idle( object sender, EventArgs e )

    {

        Application.Idle -= new EventHandler( First_Application_Idle );

        foreach( Group group in gridControl1.Groups )

        {

            SummaryRow sumRow = group.FooterRows[ 0 ] as SummaryRow;

            ValueRow valueRow = group.FooterRows[ 1 ] as ValueRow;

            if( sumRow != null && valueRow != null )

            {

                valueRow.Cells[

    “SupplierID” ].Value = sumRow.Cells[ “SupplierID” ].Value;

            }

        }

        //Time to subscribe to the ValueChanged event, so we can update the ValueRow accordingly

        dataRowTemplate1.Cells[

    “SupplierID” ].ValueChanged += new EventHandler( Form1_ValueChanged );

    }

    However, I will investigate why the virtualization of cells brings this behavior of not updating all groups correctly.

     

    Imported from legacy forums. Posted by André (had 979 views)

    User (Old forums)
    Member
    Post count: 23064

    We’ve come to the point now that we know we need a valuerow since summary row can’t display text. Valuerows are however not always updated (regardless of virtualization – please leave it on as I don’t want to confuse things, I’m just trying to get it to work) – that’s the problem now.

    To duplicate the problem:

    Create a grid linked to a dataset with a table having 3 columns (Column1 – string,Column2 – Int32,Column3 – string). Now add a group (On Column1) with a valuerow (footerrow 0) and summaryrow (footerrow 1) as footer rows for the group (Column1) in the designer. Set Column2 in the summaryrow as type int32 and statfunction = SUM. Ensure both summary and valuerows have VisibleWhenCollapsed set to true. Collapse the group and also add the code below.

    The problem here is that some of the valuerows (Column2) are NOT DISPLAYED, well sometimes and sometimes not etc. etc. I’m running 3.7.8465.14130 or the grid control.

    private void button1_Click(object sender, EventArgs e)

    {

    dataSet1.Tables[“Table1”].Rows.Clear();

    dataSet1.Tables[“Table1”].AcceptChanges();

    for (int I=0;I<20;I++)

    {

    for (int J=0;J<20;J++)

    {

    System.Data.DataRow ADataRow = dataSet1.Tables[“Table1”].NewRow();

    ADataRow[“Column1”] = I.ToString();

    ADataRow[

    “Column2”] = J+I;

    dataSet1.Tables[

    “Table1”].Rows.Add(ADataRow);

    ADataRow.AcceptChanges();

    }

    }

    }

    private

    void Form1_Load(object sender, EventArgs e)

    {

    dataRowTemplate1.Cells[

    “Column2”].ValueChanged += new EventHandler(Form1_ValueChanged);

    }

    void Form1_ValueChanged( object sender, EventArgs e )

    {

    Xceed.Grid.

    DataCell cell = sender as Xceed.Grid.DataCell;

    ACellGroup = cell.ParentRow.ParentGroup

    as Xceed.Grid.Group;

    Application.Idle += new EventHandler(Application_Idle);

    }

    void Application_Idle( object sender, EventArgs e )

    {

    Application.Idle -= new EventHandler( Application_Idle );

    if (ACellGroup != null)

    {

    if (ACellGroup.FooterRows.Count == 2)

    {

    ValueRow valueRow = ACellGroup.FooterRows[0] as ValueRow;

    SummaryRow sumRow = ACellGroup.FooterRows[1] as SummaryRow;

    if(sumRow != null && valueRow != null)

    {

    try

    {

    valueRow.Cells[

    “Column2” ].Value = sumRow.Cells[“Column2”].Value;

    }

    catch

    {

    }

    }

    }

    }

    }

     

     

    Imported from legacy forums. Posted by Comodo (had 980 views)

    User (Old forums)
    Member
    Post count: 23064

    Virtualization IS important, because the code I gave you would work fine before we implemented Virtualization in the grid.  The reason it does not work anymore is because the sequence of events has changed, and the painting is not done in all cases, and since the SummaryRow has a different mechanism to update (because it has to know the value of each cell before calculating the StatFunction), it gives inconsistent results.

    Investigating this further, we found the reason why it behaves this way, and we found a workaround. I have attached a sample application that works fine (it uses the Northwind DB that is installed by our installer, so it should work as is on Vista, but you may have to update the DB path on XP).  Basically, you have to make sure the Application.Idle event is subscribed to only once.  This means that a private variable (applicationIdlePending) can be use to do this, and it makes the following changes to the code I posted previously :

    private Group group;

    private bool applicationIdlePending = false;

    void Form1_ValueChanged( object sender, EventArgs e )

    {

        if( applicationIdlePending )

            return;

        //Get the group of the DataRow that was just updated

        DataCell cell = sender as DataCell;

        if( cell != null )

        {

            applicationIdlePending =

    true;

            group = cell.ParentRow.ParentGroup

    as Group;

            Application.Idle += new EventHandler( Application_Idle );

        }

    }

    //Do the update to the ValueRow

    void Application_Idle( object sender, EventArgs e )

    {

        Application.Idle -= new EventHandler( Application_Idle );

        if( group != null )

        {

            SummaryRow sumRow = group.FooterRows[ 0 ] as SummaryRow;

            ValueRow valueRow = group.FooterRows[ 1 ] as ValueRow;

            if( sumRow != null && valueRow != null )

            {

                valueRow.Cells[

    “SupplierID” ].Value = sumRow.Cells[ “SupplierID” ].Value;

            }

        }

        applicationIdlePending =

    false;

    }

    Imported from legacy forums. Posted by André (had 738 views)

    User (Old forums)
    Member
    Post count: 23064

    Thats very nice but does not solve my problem (Your project works perfectly). Look at the code I posted and the questions, try implementing that … THIS is where the problem is. Your fixes do solve the bigger picture … probably … but I’m not there yet. I’ve modified your project to use a unbound dataset and then I seem to get the “invisible” cells issue. Lets try solve this first … and in code that we know doesn’t work.

    1) I’ve implemented all your changes on my code and still get the problem (Invisible cells)

    2) I’ve changed tons off things on your project and only seem to get the error once I start using a unbound dataset – switching back to bound data and all’s OK.

    3) !!!! None of the events ever fire once the form is displayed, bound or unbound. Perhaps a painting issue .. I don’t know

    Sooo – I’m not saying that a unbound dataset causes the problem or the paint event or anything for that matter. Try implementing your code/solution on my problem because it might be something completey different. Ex. you did not have the groups collapsed – This could have been the issue …..

    Regards

    Imported from legacy forums. Posted by Comodo (had 909 views)

    User (Old forums)
    Member
    Post count: 23064

    The cells are normally all correct at startup – To get them messed up “easily” you must scroll up and down franticly (PgUp, PgDn). Once a cell goes blank it stays blank, even when scrolling up and down. This is relevant to my projects and yours with undbound data it seems, I’m not sure. If I run your project as is (Your ZIP) it works perfectly always – so far. I think the more data the easier to break.

    I’ve noted that UIVirtulization is not off in your project but it still seems to work. When I disable UIVirtulization on the “broken projects” things seem to work – so far. How does this impact performance (if this is the only way to get it to work) since this is a huge table I’m working with. Does this mean UIVirtulization does not work 100 %

    Imported from legacy forums. Posted by Comodo (had 720 views)

    User (Old forums)
    Member
    Post count: 23064

    OK – How about now adding rows that create new groups …… aaaaarggghh

    1) Cells still dissapear – Perhaps resolved by virtulization ?

    2) First_Application_Idle not useful when new rows are added to table and they in turn create new groups – so now we have to look at group_added event or what

     and then ….

     How about allowing text in a summarycell ?

    Imported from legacy forums. Posted by Comodo (had 841 views)

    User (Old forums)
    Member
    Post count: 23064

    What do you mean by unbound data?  In the code snippet you provided, and in the text you posted, you refer to a DataSet that you update.  I assume you are using this DataSet to bind the grid to, which is not unbound data.  Is it what your doing, or are you providing data manually to all cells in the grid?

    Imported from legacy forums. Posted by André (had 651 views)

Viewing 15 posts - 1 through 15 (of 19 total)
  • You must be logged in to reply to this topic.