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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:41:23+00:00 2026-05-18T04:41:23+00:00

Hi I have a custom BindingList Containing Products with the following information string ProductID

  • 0

Hi I have a custom BindingList Containing Products with the following information

string ProductID
int Amount;

How would I make it possible to do the following.

ProductsList.Add(new Product("ID1", 10));
ProductsList.Add(new Product("ID2", 5));
ProductsList.Add(new Product("ID2", 2));

The list should then contain 2 Products

ProductID = "ID1"   Amount = 10
ProductID = "ID2"   Amount = 7;

So It workes kind of like a Shopping Cart

Im looking at the AddingNew Event and override void InsertItem(int index, T item)

But I could really need a little help getting started

  • 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-18T04:41:23+00:00Added an answer on May 18, 2026 at 4:41 am

    i really don’t know why you require this custom list as there are many good collections in the .net library but i have tried something below.

     public class ProductList
    {
       public string ProductID {get;set;}
       public int Amount {get;set;}
    }
    
    public class MyBindingList<T>:BindingList<T> where T:ProductList
    {
    
        protected override void InsertItem(int index, T item)
        {
    
            var tempList = Items.Where(x => x.ProductID == item.ProductID);
            if (tempList.Count() > 0)
            {
               T itemTemp = tempList.FirstOrDefault();
               itemTemp.Amount += item.Amount;
    
    
            }
            else
            {
                if (index > base.Items.Count)
                {
                    base.InsertItem(index-1, item);
                }
                else
                    base.InsertItem(index, item);
    
            }
    
        }
    
        public void InsertIntoMyList(int index, T item)
        {
            InsertItem(index, item);
        }
    
    
    
    }
    

    and in the client code where you can use this list.

            ProductList tempList = new ProductList() { Amount = 10, ProductID = "1" };
            ProductList tempList1 = new ProductList() { Amount = 10, ProductID = "1" };
            ProductList tempList2 = new ProductList() { Amount = 10, ProductID = "2" };
            ProductList tempList3 = new ProductList() { Amount = 10, ProductID = "2" };
    
            MyBindingList<ProductList> mylist = new MyBindingList<ProductList>();
    
            mylist.InsertIntoMyList(0, tempList);
            mylist.InsertIntoMyList(1, tempList1);
            mylist.InsertIntoMyList(2, tempList2);
            mylist.InsertIntoMyList(3, tempList);
            mylist.InsertIntoMyList(4, tempList1);
            mylist.InsertIntoMyList(0, tempList3);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have custom slider that I use the following touch event to respond to:
I have custom placeholders in a textarea and I would like every browser to
I have custom class that implement IEnumerable<int[]> interface and save current Enumerator . When
I have overridden the ApplySortCore method for a custom BindingList like so: public void
Ok, I have my custom class: public class FileItem : INotifyPropertyChanged { int id=0;
I have custom validators and filters that I have created that I would like
I have custom UITableViewCell . It contains UITextLabel . When I press this cell
I have custom validation rule: public function customRule($check) { } Inside this rule I
I have custom classes that I currently instantiate within App.xaml as resources. I want
i have custom cell with 2 buttons(the function of these buttons is just to

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.