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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:16:59+00:00 2026-05-26T23:16:59+00:00

I am working on an Excel 2010 template project. In my template I have

  • 0

I am working on an Excel 2010 template project. In my template I have many sheets with static ListObject controls in each of them. To initialize my ListObject, I bind a BindingList<MyCustomType> so it generates a column for each of my MyCustomType public properties. It is really handy because when the user some rows in the ListObject, it automatically fills up my BindingList instance. I added a button in the Excel ribbon so that the program can validate and commit these rows through an EDM. This is how I bind my data to the ListObject in the startup event handler of one of my Excel sheet.

public partial class MyCustomTypesSheet
{
    private BindingList<MyCustomType> myCustomTypes;

    private void OnStartup(object sender, System.EventArgs e)
    {
        ExcelTools.ListObject myCustomTypeTable = this.MyCustomTypeData;
        BindingList<MyCustomType> customTypes = new BindingList<MyCustomType>();

        myCustomTypeTable.SetDataBinding(customTypes);
    }

    // Implementation detail...
}

Now my issue is that it is very likely that the user of this template will enter these rows in many sessions. It means that he will enter data, save the file, close it, reopen it, enter some new rows and eventually try to commit these rows when he thinks he is done. What I noticed is that when the Excel file created from the template is reopened, the DataSource property of my ListObject controls is null. Which means I have no way to get back the data from the ListObject into a BindingList<MyCustomType>. I have been searching and I found no automatic way to do that and I don’t really want to make a piece of code that would crawl through all of the columns to recreate my MyCustomType instances. In an ideal world I would have done like this.

private void OnStartup(object sender, System.EventArgs e)
{
    ExcelTools.ListObject myCustomTypeTable = this.MyCustomTypeData;
    BindingList<MyCustomType> customTypes = null;

    if (myCustomTypeTable.DataSource == null) // Will always be null and erase previous data.
    {
        customTypes = new BindingList<MyCustomType>();
        myCustomTypeTable.SetDataBinding(customTypes);
    }
    else
    {
        customTypes = myCustomTypeTable.DataSource as BindingList<MyCustomType>;
    }
}

I have been doing a lot of research on this but I was not able to find a solution so I hope some of your can help me to resolve this issue.

Thanks.

  • 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-26T23:17:00+00:00Added an answer on May 26, 2026 at 11:17 pm

    As a last solution I decided that I would serialize my object list in XML and then add it as a XML custom part to my Excel file on save. But when I got into MSDN documentation to achieve this, I found out that there was 2 ways to persist data: XML custom part and data caching. And actually data caching was exactly the functionality I was looking for.

    So I have been able to achieve my goal by simply using the CachedAttribute.

    public partial class MyCustomTypesSheet
    {
        [Cached]
        public BindingList<MyCustomType> MyCustomTypesDataSource { get; set; }
    
        private void OnStartup(object sender, System.EventArgs e)
        {
            ExcelTools.ListObject myCustomTypeTable = this.MyCustomTypeData;
    
            if (this.MyCustomTypesDataSource == null)
            {
                this.MyCustomTypesDataSource = new BindingList<MyCustomType>();
                this.MyCustomTypesDataSource.Add(new MyCustomType());
            }
    
            myCustomTypeTable.SetDataBinding(this.MyCustomTypesDataSource);
        }
    
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(OnStartup);
        }
    }
    

    It works like a charm. You can find more information about data caching in MSDN documentation.

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

Sidebar

Related Questions

I have been working on an Excel 2010 template for some time and I
I am working on a VSTO project using excel 2010 and visual studio 2010.
I'm working with the following RegEx function in Excel 2010 and am getting the
I have a large data set that I'm working with in excel. About 1000+
1) I have been working on fetching data from an excel sheet i can
I am working with Excel 2010. I need to create a macro, that after
When working with Excel 2010, I try to save data as an XML Data
I'm using Excel 2010, and have defined the following 3 functions in spreadsheet's Module.
I have built template-based add ins for Word and Excel version 2003 and previous.
I have an working Excel file, with file I can send data extracted from

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.