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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.