2011-10-27 34 views
1

バインディングリストBindingList<RunData>を作成してCustomMessageBox.Show()に渡しますが、DataGridViewにはリスト要素が表示されません。c#DataGridView.DataSource = BindingListが機能しない

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 
} 

は私が前に私は、私はOKすべてをしたように見えるオンラインで見つけるの例からBindingListを使用したことがありません。どんな助けもありがとう。

ありがとうございます!

EDIT

それはすべての違いを、私は、.NET 2.0を使用しています。

+0

show関数でデータソースを設定した後で、.Bind()関数が不足していませんか? –

+0

'DataSource'を設定した後、' ResetBindings() 'を呼び出すことを試みてください。 – harlam357

答えて

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 
    } 
+0

うん、それはうまくいった。不思議、私は本当にそれを内部に保ちたい。しかたがない。 – john

関連する問題