DataGridViewのDataSourceにnull値を持つObjectArrayを入れたらどのように表示されるのか試してみた。
コード
まず、Personクラスを用意。
今回試すのはint型、string型、bool型、DateTime型にした。
class Person
{
public int id { get; set; }
public string name { get; set; }
public bool sex { get; set; }
public DateTime birthday { get; set; }
}
次に、値を設定し、DataGridViewを表示。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
var persons = new List<Person>();
persons.Add(new Person() { id = 1, name = "鹿目まどか", birthday = new DateTime(2010, 10, 3), sex = false });
persons.Add(new Person() { id = 2, name = "暁美ほむら", sex = false });
persons.Add(new Person() { id = 3, name = null, sex = false });
persons.Add(new Person() { id = 4, name = "巴マミ" });
persons.Add(new Person() { id = 5, name = "佐倉杏子", sex = false });
persons.Add(new Person() { name = "キュゥべえ", sex = true });
dataGridView1.DataSource = persons.ToArray();
}
}
結果
まとめ
だいたい予想通りで、
- int型 : 0
- string型 : 空白
- bool型 : false
- birthday : 空白
で表示される。