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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:18:03+00:00 2026-05-18T03:18:03+00:00

I have the following business object: public class MyObject { // Some public properties

  • 0

I have the following business object:

public class MyObject
{
  // Some public properties that are bound to text boxes, etc on the form
  public string Customer { get; set; }
  public int JobNumber { get; set; }

  // Each DataTable in this list consists of a single column of doubles
  // representing the error in a series of measurements (ex. -.0002, -.0003, .0002, etc)
  public List<DataTable> MeasurementErrors {get; set; }

  public MyObject
  {
    // Code in here creates the first DataTable with the first measurement (always zero)
    // and adds it to the MeasurementErrors list
    errors = new DataTable();
    errors.TableName = "MeasurementErrors";
    errors.Columns.Add("Error", typeof(double));
    errors.Rows.Add(0.0);
    MeasurementErrors.Add(errors); // initial table added to the list
  }
}

I’ve had no problems binding Customer and JobNumber and all the other basic properties to text boxes on the entry form (VS generated a BindingSource and set up all those controls for me).

What I’m having trouble with is binding one of the DataTables in MeasurementErrors to a DataGridView control. The table to bind should be chosen by a NumericUpDown control and then there will be a simple “Add” button to generate a new table and add it to MeasurementErrors (and a delete button if necessary). How do I set up the DataSource and DataMember properties of the DataGridView to bind to MeasurementErrors[value of UpDownControl]?

I’m not fixed on using DataTables but from what I’ve read that is the preferred way of binding to a DataGridView.

  • 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-18T03:18:04+00:00Added an answer on May 18, 2026 at 3:18 am

    A List<T> is not bindable. Use an IList<T> instead as the property return type.

    public IList<DataTable> MeasurementErrors { get; set; }
    

    Plus, it is better recommended to use a internal list for list members and make it a read-only property, depending on your needs, always.

    public class MyObject {
        private IList<DataTable> _measurementErrors;
    
        public MyObject() {
            _measurementErrors = new List<DataTable>();
        }
    
        // This way you make sure to never have a null reference, and don't give 
        // out the control over your list to the user.
        public IList<DataTable> MeasurementErrors {
            get {
                return _measurementErrors;
            }
        }
    }
    

    EDIT #1

    IList doesn’t seem to be serializable so it is simply left out of the resulting xml file. Is there a simple way to make this IList serializable?

    If your instance of IList<T> is a List<T> under the hood, then I suggest you to type-cast your IList<T> to a List<T> for the sake of serialization. And if that fails, then create a new list from its content.

    var list = myObject1.MeasurementErrors as List<DataTable> ?? new List<DataTable>(myObject1.MeasurementErrors);
    

    For more details about ?? Operator, please refer to MSDN: ?? Operator (C# Reference)

    In short, it is the equivalence of writing:

    var list = (myObject1.MeasurementErrors as List<DataTable>) == null ? 
                new List<DataTable>(myObject1.MeasurementErrors) : 
                myObject1.MeasurementErrors as List<DataTable>;
    

    Or if you prefer:

    var list = myObject1.MeasurementErrors as List<DataTable>;
    
    if (list == null)
        list = new List<DataTable>(myObject1.MeasurementErrors);
    

    I hope this information is not more confusing than helping.

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

Sidebar

Related Questions

i have the following directories: -UI -BusinessLogic -DataAccess -BusinessObjects if i have a class
I have following string String str = replace :) :) with some other string;
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have a visual studio solution with the following projects: UI DataAccess BusiessLogic BusinessObjects
I have a VS solution, with the following projects. -GUI -DataAccess -BusinessLogic -BusinessObjects but
I have the following table in MSSQL2005 id | business_key | result 1 |
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have following situation. A main table and many other tables linked together with
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party

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.