Jump to content
  • Advertisement
Sign in to follow this  
CodeMachine

[.net] Sort column in dataview

This topic is 4582 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I have a column in a dataview that I want to sort. The datatype is string. The values are like: "0 %" "10.2 %" etc How do I implement sorting on values like those? I can not convert the datatype to int (and skip %). But if I have int's, you sort like "dataview.sort = 'mycolumn DESC'". Now I want integer sorting on those strings above. Does anyone have information about how to implement this sort? (Im using VS2003) Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Right now I get the information from a database.
Then I calculate the values (0%, 10.5% for instance) for each row (the calculation is done when doing a search).

So yes, I can do the sort in that step, but it should be possible to do it another way too :)
I've used the property "ListView.Sort" earlier (when having datatype=double). But now I've changed it to String). So I want to use the "same" sorting-method.

A few places are dependent on this kind of sort (the data-layer is not sorted, but
the presentation layer is (via the property ListView.Sort)).
So I do not want to change the order of the data-layer. Only the presentation-layer.

Isn't it possible to create a class that extends from IComparable (implement Compare(object, object))? And then having all rows compared, using that method?

Share this post


Link to post
Share on other sites
Hello Strider

It is possible to use BoundColumn and its property DataFormatString, to give the presentation layer another look (the data is double, but the presentation will be string (% added)).

This is possible in web-development.
But I can't find a similiar solution in application-development.

Do you have (or anybody else) any ideas?

Share this post


Link to post
Share on other sites
Well, this whole sort thing was fixed in .NET 2.0, you can actually sort text using the "dataview.sort = 'mycolumn DESC'" example you gave a couple days ago. I'm gonn have to look into it some more honestly.

Share this post


Link to post
Share on other sites
Hi again

I found one property of the DataGridTextBoxColumn class:
DataGridTextBoxColumn.Format = "#.000 %";

"#.000 %" gives 3 decimals and adds a % sign next to the value.
So, this is one solution I found.

Much less job than having it done by implementing a custom comparer :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!