Home Forums WinForms controls Xceed Grid for WinForms How can I add a SummaryRow to a grid? C#

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

    Hello there:

    I’m using an unbound grid that later on the program is loaded with data from a dataSet.
    (there are several dataSets from where to load the grid.

    So far so good…

    Since the grid is used to print a report, I need to add a summaryRow to a column named “COST”, but I dunno how to do this.

    I already added a summary row to the grid, (at design time), and I added a summaryCell with code.

    When I use :

    this.summaryRow1.Cells.Add(this.cellsumCOST)

    I get a : “Cannot add an item to a ReadOnly or FixedSize list.” error.

    This is what I use to attempt to create the summaryRow (the dataSet has been previously filled) :

    private Xceed.Grid.SummaryCell cellsumCOSTO;
    private Xceed.Grid.SummaryRow summaryRow1;

    this.cellsumCOST = new Xceed.Grid.SummaryCell();
    cellsumCOST.StatFieldName = “COST”;
    cellsumCOSTO.StatFunction = Xceed.Grid.StatFunction.Sum;
    cellsumCOST.Initialize(“COST”);
    this.summaryRow1.Cells.Add(this.cellsumCOST)

    I hope somebody can help me …

    Thanks in advance!!

    Imported from legacy forums. Posted by chip (had 3911 views)

    User (Old forums)
    Member
    Post count: 23064

    You don’t need to add a SummaryCell. It is created for every column when you drop the SummaryRow in the designer. Moreover, if you add a column at run time, it will also create the corresponding cell for the SummaryRow.

    So you simply need to get a reference to the cell you want, and set it up.

    e.g.:

    SummaryCell cellsumCOST = this.summaryRow1.Cells[ “COST” ];

    //then setup the cell
    cellsumCOST.StatFieldName = “COST”;
    cellsumCOST.StatFunction = Xceed.Grid.StatFunction.Sum;

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

    User (Old forums)
    Member
    Post count: 23064

    Hello André :

    I did as you said, but now I get a message that says I can not convert implicity an Xceed.Grid.Cell to Xceed.Grid.SummaryRow.

    I know I’m missing something (I’m a noob) but dunno what is it…

    Sorry to bother you with these questions, but I need to get this done so I can get my boss aproval to buy this component…

    Thanks in advance !!!

    Imported from legacy forums. Posted by chip (had 446 views)

    User (Old forums)
    Member
    Post count: 23064

    On which line do you get this message?

    You are trying to cast a cell to a row. You need to cast a cell to a cell, or a row to a row. Moreover, in certain cases when trying to get a reference to a cell or a row, you need to make an explicit cast so the compiler will not complain, because the collection is not typed.

    e.g. :

    Xceed.Grid.DataRow row = ( Xceed.Grid.DataRow )gridControl1.CurrentRow;

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

    User (Old forums)
    Member
    Post count: 23064

    Hey thanks a lot for your help André!!

    It is now up & running !! I got the approval from my boss and as soon as I get the cash I’ll be buying this component! 🙂

    Now I just have a simple question..

    How can I make this sumCell to display when a user groups columns??

    I tried looking on the forums but I guess the search function is not working..I always get “page not found” and it’s sort of difficult to search page by page…

    Thanks a lot man!!!!

    Chip

    Imported from legacy forums. Posted by chip (had 362 views)

    User (Old forums)
    Member
    Post count: 23064

    You will need to add it dynamically as the user groups/ungroups the grid. You can use the GroupingUpdated event, and do something like the following in the event handler :

    private bool justUpdated = false;

    private void gridControl1_GroupingUpdated(object sender, EventArgs e)
    {
    if( !justUpdated )
    {
    foreach( Group group in gridControl1.GroupTemplates )
    {
    if( group.GroupBy != “OrderID” && group.GroupBy != “Quantity” && group.GroupBy != “Discount” )
    {
    bool summaryPresent = false;
    foreach( Row row in group.FooterRows )
    {
    if( row is SummaryRow )
    {
    summaryPresent = true;
    }
    }
    if( !summaryPresent )
    {
    SummaryRow sumRow = new SummaryRow();
    group.FooterRows.Add( sumRow );
    if( group.GroupBy == “ProductID” )
    {
    sumRow.TextFormat = “Quantity : %SUM: Quantity%”;
    }
    else if( group.GroupBy == “UnitPrice” )
    {
    sumRow.TextFormat = “Discount : %AVG: Discount format=\”0.##\”%”;
    }
    //else if…
    justUpdated = true;
    gridControl1.UpdateGrouping();
    }
    }
    }
    }
    else
    {
    justUpdated = false;
    }
    }

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

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