1

I create a binding list BindingList<RunData> and pass it through CustomMessageBox.Show() but the DataGridView doesn't display the list elements.

public partial class CustomMessageBox : Form
{
    #region Fields.

    private static CustomMessageBox customMessageBox;

    private static String selectedDateTime;

    #endregion

    #region Properties.

    internal String SelectedDateTime
    { get { return CustomMessageBox.selectedDateTime; } }

    #endregion

    #region Constructors.

    private CustomMessageBox()
    {
        InitializeComponent();            
    }

    #endregion

    #region Methods.

    internal static DialogResult Show(BindingList<RunData> dataGridViewData)
    {
        CustomMessageBox.customMessageBox = new CustomMessageBox();
        CustomMessageBox.customMessageBox.dataGridViewRunData.AutoGenerateColumns = true;
        CustomMessageBox.customMessageBox.dataGridViewRunData.DataSource = dataGridViewData;            
        return CustomMessageBox.customMessageBox.ShowDialog();            
    }

    #endregion
}

internal class RunData
{
    #region Fields.

    private String dateTime;

    private String name;

    private String product;

    private String result;

    #endregion

    #region Properties.

    internal String DateTime
    { get { return this.dateTime; } }

    internal String Name
    { get { return this.name; } }

    internal String Product
    { get { return this.product; } }

    internal String Result
    { get { return this.result; } }

    #endregion

    #region Constructors.

    internal RunData(String dateTime, String name, String product, String result)
    {
        this.dateTime = dateTime;
        this.name = name;
        this.product = product;
        this.result = result;
    }

    #endregion
}

I have never used BindingList before but from the examples I found online it looks like I did everything OK. Any help would be appreciated.

Thanks!

EDIT

I'm using .NET 2.0 if that makes any difference.

2
  • Aren't you missing a .Bind() function after you set the datasource in the show function?? Commented Oct 27, 2011 at 17:28
  • Try calling ResetBindings() after setting the DataSource. Commented Oct 27, 2011 at 17:43

1 Answer 1

5

In my testing I have found that the model class (i.e. RunData) and or properties should be Public not internal.

I created a sample class and did the same setup you have with your grid. It failed with internal properties and class. Once I made it public it was fine.

  public class RunData
  {
        #region Fields.

        private String dateTime;

        private String name;

        private String product;

        private String result;

        #endregion

        #region Properties.

        public String DateTime
        { get { return this.dateTime; } }

        public String Name
        { get { return this.name; } }

        public String Product
        { get { return this.product; } }

        public String Result
        { get { return this.result; } }

        #endregion

        #region Constructors.

        public RunData(String dateTime, String name, String product, String result)
        {
            this.dateTime = dateTime;
            this.name = name;
            this.product = product;
            this.result = result;
        }

        #endregion
  }
Sign up to request clarification or add additional context in comments.

1 Comment

Yep, that worked. Strange, I really want to keep it internal. Oh well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.