ComanderKai77
ComanderKai77

Reputation: 492

c# dataGridView null reference exception

I'm using this code:

DataTable table = new DataTable();
table.Columns.Add("Title");
dataGridView1.DataSource = table;

to populate my dataGridView but I get a null reference exception when I set the datasource.

Upvotes: 2

Views: 529

Answers (1)

Kai van Lopik
Kai van Lopik

Reputation: 246

Your dataGridView1 is most likely a NULL reference. To verify, set a breakpoint on the line and when you hit it, hover your mouse over dataGridView1.

Upvotes: 4

Related Questions