开发者

Order datagrid image cells like numeric cells? Possible?

开发者 https://www.devze.com 2023-04-03 12:05 出处:网络
Basically I have a DataGrid, that disp开发者_运维技巧lays numbers and some numbers need to be represented as images.

Basically I have a DataGrid, that disp开发者_运维技巧lays numbers and some numbers need to be represented as images.

My DataGrid uses DataTable as its source. I have both (int) cells and (image) cells in DataTable. When I click on the header of an int cell in DataGrid, it gets ordered correctly in order, however image cells obviously get ordered in random.

Is it possible to give cell two 'values'? one that holds the actual value, so it can be ordered and another one that contains what to display (image, string cell)? if that makes sense.

Is there another way how accomplish what I'm trying to do? Thanks!

EDIT: Also, when I order regular int cells, if some cells are empty, they get first in the order. Like:

(Empty)
(Empty)
(1)
(2)
(4)
(6)
(7)

How can I make them appear last?


I'm assuming this is a WinForms Datagrid, but you should be able to find similar answers for an ASP.Net one as well.

Have a look at custom sorting for grids. Specifically, you can handle the SortCompare event, where you should have the necessary information to intercept the sort based on the image field, and just sort using the int field rather (perhaps use the Column property on the DataGridViewSortCompareEventArgs object provided to check which column is being sorted on, in conjunction with the RowIndex1 and RowIndex2 and the original data source to get the alternate column values you need).

Regarding your null sorting problem, you should be able to work that out using a custom sort as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消