JacekRobak85
JacekRobak85

Reputation: 93

Sorting in DataGridView throws NullReferenceException

Dear Colleagues

I have a problem with sorting in DataGridView module. When i click on column which needs to be sort then system throws NullReferenceException. I understand that column has some null values and this couses error message. Have You got any idea how to change sort module to thread null values as string without any characters?

Your prompt will be appreciated.

Upvotes: 0

Views: 911

Answers (3)

JacekRobak85
JacekRobak85

Reputation: 93

Dear Geaorge and Mamta

Thank You both once again for help. I have found solution which ease resolved problem. As I wrote, all data is transfered from database to visual studio, so I changed query from:

"SELECT number_of_invoice FROM invoices"

to:

"SELECT CASE WHEN (number_of_invoice is null) then '' else number_of_invoice END FROM invoices"

This automaticly change null values to '', and problem is dismissed.

Have a good day!

Upvotes: 0

Mamta D
Mamta D

Reputation: 6460

I know this is a bit complicated for your need but you could try a workaround similar to this after programmatically selecting those rows that have nulls in them.

Sorting selected rows in DataGridView

Upvotes: 1

george.zakaryan
george.zakaryan

Reputation: 980

Why not use an empty string instead of null strings?

Upvotes: 1

Related Questions