This is a migrated thread and some comments may be shown as answers.

Sort a column with value of other column

5 Answers 148 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Geert
Top achievements
Rank 1
Geert asked on 06 Jul 2010, 11:03 AM
Hello,

I have a gridview containing a file explorer. For the column filesize I have a hidden column with the filesize in bytes. The I have another column with the size formatted to a string containing 8,25 KB, ...

When the user wants to sort the data by the filesize column, I have to sort dynamicly on the hidden column instead of the filesize column.

Is there a way of doing this?

Tnx!

5 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 06 Jul 2010, 04:14 PM
Hello Geert,

Thank you for contacting us.

Please consider the following forum thread. I have tested it and it worked fine one my end.

A bit off topic, please ask the purchase holder for our products in your company to add you as a License Developer to the license. This will give you full access to the products your company has purchased, to our downloads section, and to our support ticketing system. Additionally, all your questions will be reviewed according to the license you have. More information on License Developers you can find here: www.telerik.com/account/faqs.aspx.

Best wishes,
Stefan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Geert
Top achievements
Rank 1
answered on 07 Jul 2010, 08:21 AM
Hello Stefan,

I've added me as developer in our license. 

With the setting of the datatype of the column, the problem is not solved. In My column there is a decimal followed by a string

8,43 KB
10,2 MB
...

When I set the datatype the decimal and bind the data to the grid an error shows up...
0
Stefan
Telerik team
answered on 07 Jul 2010, 12:32 PM
Hi Geert,

Thank you for your reply. 

If I understood you correctly, you have a HiddenDecimalColumn, and a TextBoxColumn that represents the value of the decimal column plus a string ("KB"/"MB"), and you want to have appropriate sorting by clicking on the TextBoxColumn.  

You have two approaches here:

The first approach (the easiest one) is to make your HiddenDecimalColumn which contains the decimals visible, and to use this code snippet
 
byteColumn.FormatString = "{0:##.###} KB";
 
to format the displayed text on the way you want. In this case the sorting will work properly, and you don't need TextBoxColumn.

About the second approach, which is more complicated and not perfect, you have to override the OnMouseDownLeft method to check if the clicked header element is the TextColumn (the representation of the decimals values as strings) and if it is, to sort the grid according to the HiddenDecimalColumn. I am attaching a sample project where you could see this. 

Please note that when using the second approach, the HeaderElement (of the TextColumn) will not indicate the sorting (the small arrow indicating ASC or DESC order will not appear). What I can suggest is to catch the CellFormating and for make a custom formatting for the sorted column, if you prefer this approach.

If you have any other questions, do not hesitate to contact us.

 

Kind regards,
Stefan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Vahagn Hokhikyan
Top achievements
Rank 1
answered on 31 Jan 2011, 10:53 PM
Thank you for posting the example Stefan, since I have a similar issue and can use provided code. Just to be clear, I will be using the OnMouseDownLeft approach since mine is not a formatting issue. When one of my column headers is clicked I will be sorting the grid on 3 hidden columns. I see how to do it using the code you provided but I would also like to be able to get the sorting glyph on the column header to indicate what direction the column is sorted.

When I enable the soring on my visible column (it is an unbound column) the gridview sorts on my 3 hidden columns and at the end goes back to unsorted mode again. I think this is because a sorting is being attempted on my visible column which resets the sort descriptors. How can I detect that a sort on my visible column is firing in the SortChanging event to cancel it? 

Thank you!
0
Stefan
Telerik team
answered on 03 Feb 2011, 01:56 PM
Hello Vahagn Hokhikyan,

Thank you for writing.

In order to implement your scenario you can disable the sorting for the visible column by using the OnMouseDownLeft which allows you to detect when sorting is called on this column. Then, in the OnMouseDownLeft simply add the necessary group descriptors and the grid will be sorted by the hidden columns. This way you do not need to cancel the filtering for the visible column because it is already disabled.

See the attached sample for more details.

Let me know if you need further assistance.
 
Greetings,
Stefan
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
Tags
GridView
Asked by
Geert
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Geert
Top achievements
Rank 1
Vahagn Hokhikyan
Top achievements
Rank 1
Share this question
or