简体   繁体   English

c#dataGridView空引用异常

[英]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 . 填充dataGridView但是在设置datasource时出现null reference exception

Your dataGridView1 is most likely a NULL reference. 您的dataGridView1最有可能是NULL引用。 To verify, set a breakpoint on the line and when you hit it, hover your mouse over dataGridView1. 要进行验证,请在该行上设置一个断点,然后单击该断点,将鼠标悬停在dataGridView1上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM