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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:11:09+00:00 2026-06-09T02:11:09+00:00

Using C# WinForms in VS 2008 (.Net 3.5) I am trying to bind a

  • 0

Using C# WinForms in VS 2008 (.Net 3.5)

I am trying to bind a list, that may be empty, to a data grid.

If the list has elements, and AutoGenerateColumns is enabled, the data binds to the list and everything works fine.

However, if the list is empty, or if the list becomes empty (by deleting the last element) nothing at all is display, just the gray background.

If I create the columns manually, such as:

                if (m_DataGrid.AutoGenerateColumns == false)
                {
                    foreach (var pair in objData.PropertyDataTable
                        .Where(pair => pair.Value.IsNative == true
                                    && pair.Value.IsList == false))
                    {
                        string propertyName = pair.Key;
                        PropertyData propertyData = pair.Value;

                        if (propertyData.Type == typeof(bool))
                        {
                            var column = new DataGridViewCheckBoxColumn()
                            {
                                Name = propertyName,
                                HeaderText = propertyName,
                                DataPropertyName = propertyName,
                                ValueType = propertyData.Type,
                            };
                            m_DataGrid.Columns.Add(column);
                        }
                        else
                        {
                            var column = new DataGridViewTextBoxColumn()
                            {
                                Name = propertyName,
                                HeaderText = propertyName,
                                DataPropertyName = propertyName,
                                ValueType = propertyData.Type,
                            };
                            m_DataGrid.Columns.Add(column);
                        }
                    }
                }

The columns appear, and I am able to add a new row, but the data is not actually bound, and no default values for the rows are populated like they normally are when the columns are auto generated.

When I leave the view and return, the added lines remain, but the data is not preserved.

Comparing the auto generated columns to the manually created columns in the debugger, the only property that is different between the two is the IsDataBound property on the DataGridViewColumn base class.

IsDataBound is set to true when AutoGenerateColumns is enabled, with one or more elements in the list, but is false is the list has zero initial elements, despite the DataPropertyName properties of the column being properly set.

Is there any way to to bind an empty list to a data grid, and allow the users to add rows to the blank list, with everything properly bound?

I’ve even tried adding an element to an empty list before binding, to have it auto generate and bind the columns… but as soon as the row is removed the columns disappear and the bindings are lost.

Other Implementation Details:

I am trying to bind a data source which is a custom List/Collection type that inherits from:

 - ICustomTypeDescriptor
 - IBindingList
 - ICancelAddNew
 - IList<T>
 - ICollection<T>
 - IEnumerable<T>
 - IList
 - ICollection
 - IEnumerable

The objects in the list are dynamic objects which inherit from ICustomTypeDescriptor, and map properties to values in a dictionary. The types are defined in an ObjectDefinition class that knows the available property info for the dynamic types (Property names, types, attributes, etc…)
Each list has a definition assigned to it, so that every object in the list has the same definition.

I don’t think this matters, because as long as there is at least one element in the list everything is properly bound, and works fine.

  • 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-06-09T02:11:10+00:00Added an answer on June 9, 2026 at 2:11 am

    For lists, it isn’t ICustomTypeDescriptor that rules, but ITypedList. Implement this at the list level, and you can supply your properties at runtime as you see fit. Because this doesn’t depend on any rows, it should work even for zero rows.

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

Sidebar

Related Questions

Using: Microsoft SQL Server 2008 Microsoft Visual Studio 2010 C# .NET 4.0 WinForms Ok
We are developing a multilingual Winforms application using visual studio 2008. I am trying
I am developing a Client-Server application using C# .NET Winforms with SQL Server 2008.
I need to impersonate a user in a VB.NET 2008 WinForms application, so that
I have a simple winforms application in VB.NET 2008. I am using a form
I am using .Net (C#, WinForms, Linq to SQL, SQL Server 2008) to develop
I developed a WinForms application (using C#, with visual studio 2008) and I have
I'm using winforms and I've got a comboBox that represents an IQueryable. Below the
This is a C++/CLI WinForms project targeting the .NET 2.0 framework. I am using
I'm trying to make a TextBox with syntax highlighting (for (HTML/CSS) in VB.NET 2008.

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.