として定義されたに基づいて列を自動生成するSystem.ComponentModel
などのプロパティ属性を使用しようとしていますが、データセットごとに手動で挿入せずに列の種類を変更する方法を理解するのに問題があります。以下に例を示します。[Browsable(true)]
Datasource
BindingList<clsTestRow>
テストフォーム:
public partial class Form1 : Form
{
public BindingList<clsTestRow> ds = new BindingList<clsTestRow>();
public Form1()
{
InitializeComponent();
this.dgvTester.AutoGenerateColumns = true;
this.dgvTester.DataSource = this.ds;
this.ds.Add(new clsTestRow(1, DateTime.Now));
this.ds.Add(new clsTestRow(2, DateTime.Now));
this.ds.Add(new clsTestRow(3, DateTime.Now));
this.ds.Add(new clsTestRow(4, DateTime.Now));
this.ds.Add(new clsTestRow(5, DateTime.Now));
this.ds.Add(new clsTestRow(6, DateTime.Now));
this.ds.Add(new clsTestRow(7, DateTime.Now));
this.ds.Add(new clsTestRow(8, DateTime.Now));
this.ds.Add(new clsTestRow(9, DateTime.Now));
this.ds.Add(new clsTestRow(10, DateTime.Now));
this.ds.Add(new clsTestRow(11, DateTime.Now));
}
private void Form1_Load(object sender, EventArgs e)
{
this.dgvTester.Refresh();
}
}
データ項目:
public class clsTestRow
{
private int id = 0;
private DateTime date = DateTime.Now;
[Browsable(true)]
public int Id { get { return this.id; } set { this.id = value; } }
[Browsable(true)]
public DateTime Date { get { return this.date; } set { this.date = value; } }
public clsTestRow(int _id, DateTime _date)
{
this.id = _id;
this.date = _date;
}
}
この MSDN リンクから取得したカスタム列。
出力は以下のとおりです。Datasource
これには、編集時に日付列のカレンダー コントロールがありません。これは、それを結び付けるための配線がないため予想されます。値を割り当てるたびにスキーマを手動で適用せずに接続する方法を決定しようとしています。値を使用するとAutoGenerateColumns
、文字列以外の型に対してこれを変更する方法がいくつかあります。