Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 781395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:13:21+00:00 2026-05-14T20:13:21+00:00

Does anyone know of a way to inject rows into a Silverlight DataGrid? I

  • 0

Does anyone know of a way to inject rows into a Silverlight DataGrid? I need a way to add totals rows after every 6 entries. The totals are for all rows above the summary row, not just the previous six.

I’ve tried doing it with grouping but that only shows the totals for the group and displays the totals rows above the actual rows. I would prefer to use a DataGrid for this if possible, but all solutions are welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:13:21+00:00Added an answer on May 14, 2026 at 8:13 pm

    Okay, I have a solution for you; however, it contains some funky math kung fu and so I am not sure whether it is the best solution. It does, however, work with a DataGrid.

    public void PopulateAndSum()
        {
    
            //Ugly Math Kung Fu starts here
            //Get the number of rows in the collection
            int rowCount = Items.Count;
    
            //Here you specify after how many rows should the summation occur
            int numRowsToSum = 6;
    
            //Now the idea is to loop through the collection the same number of times
            //As you would be inserting summation rows into the collection
            //To calculate the maximum number of times you should circulate you
            //divide through the number of rows and ceil the result. Make sure
            //divide by a double or at least cast one of them to a double so you do
            //not get integer division
            for (int i = 0; i < Math.Ceiling(((double)rowCount) / numRowsToSum); i++)
            {
                //Now you want to calculate the position where you need to insert the the new entry
                int index = 0;
    
                //Check whether you are still in the bounds of the array or whether you have actually reached the last element
                //in the array. This should always be the case if your collection contains a multiple of numRowsToSum
                if (numRowsToSum + i * (numRowsToSum) <= rowCount)
                {
                    //The index starts at numRowsToSum because you start the collection indexing at 0
                    //From there you jump the next index and add one to take into account that you inserted a new element
                    index = numRowsToSum + i*(numRowsToSum + 1);
                }
                else
                {
                    //If your collection contains a number of elements that are not a precise multiple of numRowsToSum
                    //then you have to have a special condition where you calculate the index for the last few elements
                    //Here you need to jump back to the previous index and add the number of elements left in the collection
                    //You also have to add 1 to take into account that you are adding an extra row.
                    index = numRowsToSum + (i - 1) * (numRowsToSum + 1) + 1 + rowCount % numRowsToSum;
                }
    
                //Now you sum all the rows before the index
    
                int sum = 0;
                for (int j = 0; j < index; j++)
                {
                    //If you want to add the previous totals to the sum comment the next part out
                    if ((j - numRowsToSum) % (numRowsToSum + 1) == 0)
                        continue;
    
                    sum += Items[j].Value;
                }
    
                //Now add the entry
                Items.Insert(index, new Info() { Name = "Total", Value = sum });
            }
        }
    

    Items is an ObservableCollection and Info is just a test class I created. I did comment the code quite thoroughly. It is more generic than your requirement in the sense that you can change the numRowsToSum to any value and it should still work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know a way to execute a bulk dump of every email of
Does anyone know a way to have all the rows of one column of
Does anyone know a way to test the migration itself after writing it? Very
Does anyone know a way to convert a month, year, and day into the
Does anyone know a way to auto-generate database tables for a given class? I'm
Does anyone know a way to find out programatically which physical disk holds a
does anyone know a way to call a generic method of a base class
Does anyone know a way to open up an instance of the operating system
Does anyone know a way to get the mean amplitude of a .wav file
Does anyone know a way to get Firefox to crop the corners if the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.