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 7542913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:17:37+00:00 2026-05-30T08:17:37+00:00

I have an interesting issue with inserting rows of data into a dataview. I

  • 0

I have an interesting issue with inserting rows of data into a dataview. I receive a set of data from the database. This information is grouped. There are three levels from this data set. For example:

Category SaleValue
    SubCategory1 SaleValue
        SubCategory2 SaleValue
        SubCategory2 SaleValue
    SubCategory1 SaleValue
    SubCategory1 SaleValue
Category SaleValue
    ...

I have assigned integer values for the grouping. Category = 0, SubCategory1 = 1, SubCategory2 = 2. This returns a nice DataView with all of the correct information.

My problem lies in how to insert new data at specific indexes. There is one more level of data for the report. There is one final level of data that I retrieve. This consists of products for each level. For example (building off the above example).

Category SaleValue
    SubCategory1 SaleValue
        SubCategory2 SaleValue
            Product SaleValue
            Product SaleValue
        SubCategory2 SaleValue
            Product SaleValue
    SubCategory1 SaleValue
    SubCategory1 SaleValue
Category SaleValue
    ...

I need to join in this data into the appropriate sections. However, I feel that somehow when I am inserting with my current code, the inserts are throwing the DataView indexes way off. Here is what I have so far. Please forgive me if I am completely missing something. I am new to DataViews.

private DataView AddProducts(DataView data)
{
    int position = 0;
    for (int i = position; i < data.Count; i++)
    {
        DataRowView currentRow = data[i];
        if (current.Row.Field<int>("group") == 2)
        {
            var productData = //DB call for data
            foreach (DataRowView row in productData)
            {
                position = i+1; //Dont want to insert at the row, but after.
                DataRow newRow = data.Table.NewRow();
                newRow[0] = row["ProductName"];
                newRow[1] = row["Sale"];
                data.Table.Rows.InsertAt(newRow, position);
                // i is now position. This will allow another insert to insert on the
                // next row, or for the loop to start at the row after this inserted
                // row.
                i = position;
            }
        }
    }
    return data;
}

This just seems like I am missing something. Maybe because I am setting the upper bounds of the loop to be the original data.Count number? Is the insert messing up the indexes? Because when I check a higher index than where I inserted, the inserted data seems to be repeated or not inserted at the right indexes.

  • 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-30T08:17:38+00:00Added an answer on May 30, 2026 at 8:17 am

    It might be easier to use a ObservableCollection and a CollectionViewSource.
    Use ObservableCollection.Add(item) and then refresh the CollectionViewSource which will automatically sort and group the data if you have the sorting and grouping setup correctly.

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

Sidebar

Related Questions

I have ran into an interesting issue while trying to create a more usable
I have an interesting issue where a class inherits from a class that implements
I have run into an interesting issue using PHP's date() function. Haven't had any
I ran into an interesting issue today. I have canvas elements that I am
So we ran into an interesting issue today. We have a Java EE web
I have an interesting issue with HTTPS ports not being handled properly. It is
Someone please help. I have an interesting issue. I am trying to implement an
I have found an interesting issue in windows which allows me to cause the
I have a rather interesting issue with SVG animation. I am animating along a
I met an interesting issue about C#. I have code like below. List<Func<int>> actions

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.