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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:14:10+00:00 2026-06-14T11:14:10+00:00

There are a Dependency class with some properties class Dependency: { public string ArtifactId

  • 0

There are a Dependency class with some properties

class Dependency:
{
     public string ArtifactId { get; set; }
     public string GroupId { get; set; }
     public string Version { get; set; }

     public Dependency() {}
}

and ProjectView class:

 class ProjectView:
 {
     public string Dependency[] { get; set; }
        ...
 }

I want to bind array of Dependencies from ProjectView class to DataGridView.

 class Editor
 {
     private readonly ProjectView _currentProjectView;

     ... //I skipped constructor and other methods  

     private void PopulateTabs()
     {
        BindingSource source = new BindingSource {DataSource = _currentProjectView.Dependencies, AllowNew = true};
        dataGridViewDependencies.DataSource = source;
     } 
  }

But when I’m binding like that, then exception occurs (AllowNew can only be set to true on an IBindingList or on a read-write list with a default public constructor.), because _currentProjectView.Dependencies is array, and it can’t be able to add new items.
There is solution is convert to list, but it is not convenient, because it’s just copy and lost reference to origin array. Is there solution of this problem? How to bind properly array to datagridview?
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-06-14T11:14:11+00:00Added an answer on June 14, 2026 at 11:14 am

    Okay, so let’s say you had an array of those Dependency objects in memory somewhere, and you did something like this:

    arrayOfObjs.ToList();
    

    That’s not going to change the reference they point to. So, to further that point, the array they came from, if it were persisted in memory, it would see the changes made. Now, will you see any additions, no? But that’s why you use a mutable type like a List instead of an array.

    So, my recommendation is that you do this:

    class ProjectView:
    {
        public string List<Dependency> Dependencies { get; set; }
    }
    

    And dump the array. If the original list of Dependency is coming from an array, well then just issue the ToList method on it and dump it. When you want to get an array back out of it (maybe you need to pass an array back), just do this:

    projectViewObj.Dependencies.ToArray();
    

    That will build Dependency[] for you.

    EDIT

    So consider the following structure:

    class ProjectView:
    {
        public Dependency[] Dependencies { get; set; }
    
        public List<Dependency> DependencyList { get { return this.Dependencies.ToList(); } }
    }
    

    Then in the form:

    private void PopulateTabs()
    {
       BindingSource source = new BindingSource { DataSource = _currentProjectView.DependencyList, AllowNew = true};
       dataGridViewDependencies.DataSource = source;
    }
    

    And then when editing is finished:

    _currentProjectView.Dependencies = _currentProjectView.DependencyList.ToArray();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class with 3 dependency properties A,B,C. The values of these properties
If I have a class with some read-only properties that are populated by a
I have a class named Data with some public members: Name , Age ,
I have a class, which returns three properties. First property is dependent on some
I have the following problem: 1) There is some abstract class A with several
Assume a class Foo , with a dependency Bar which is injected by some
There is some information in the tomcat engine that we want to access run
One problem in large C++ projects can be build times. There is some class
I created a custom ToggleButton class, ToggleButtonEx, that extends ToggleButton. ToggleButtonEx contains some dependency
Are there any Guice like or similar dependency injection frameworks in PHP? If not

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.