简体   繁体   English

在DataGridView中排序会抛出NullReferenceException

[英]Sorting in DataGridView throws NullReferenceException

Dear Colleagues 亲爱的同事们

I have a problem with sorting in DataGridView module. 我在DataGridView模块中排序有问题。 When i click on column which needs to be sort then system throws NullReferenceException. 当我点击需要排序的列时,系统会抛出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 在DataGridView中对选定的行进行排序

Dear Geaorge and Mamta 亲爱的Geaorge和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: 正如我写的,所有数据都从数据库转移到visual studio,所以我改变了以下的查询:

"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! 祝你有美好的一天!

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

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