1

バインディング リストを作成してBindingList<RunData>渡しますCustomMessageBox.Show()DataGridView、リスト要素が表示されません。

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
}

これまで使用BindingListしたことはありませんが、オンラインで見つけた例からすると、すべて問題なく実行できたようです。どんな助けでも大歓迎です。

ありがとう!

編集

違いがある場合は、.NET 2.0 を使用しています。

4

1 に答える 1

5

私のテストでは、モデル クラス (つまり、RunData) やプロパティは内部ではなくパブリックにする必要があることがわかりました。

サンプル クラスを作成し、グリッドで同じ設定を行いました。内部プロパティとクラスで失敗しました。公開したら治りました。

  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
  }
于 2011-10-27T21:57:20.870 に答える