简体   繁体   中英

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.

为什么不使用空字符串而不是空字符串?

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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