0

Hi Everyone,

I'm having problems with Datagridview Column

I have a dataset containing a table called Inventory, which i databound to my datagridview.

At my form load event, i set one column's backcolor to blue like this-

dgvBrowseBooks.Columns("Title").DefaultCellStyle.BackColor = Color.

But when i run the program, i get this error "NullReferenceException"- Object reference not set to an instance of an object.

Please what might be the problem?

Thanks

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by MeSampath
0

Hi,

Few clarifications;

1) Are you populating datagrid in the form load event or some other button clicks?
2) All the datagrid columns are predefined or assigned from dataset?

The basic idea is, the error "NullReferenceException- Object reference not set to an instance of an object" will arise when an object is null and we are trying to access the properties of null object. In this case, "dgvBrowseBooks.Columns("Title")" may be NULL and you are trying to assign a color for that by "DefaultCellStyle.BackColor" property.

So let us know if this helps.

Thank you.

Good luck.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.