473,408 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

DataGrid or DataView custom sorting

I set up sorting by various columns for a DataGrid. For one of the columns,
I would like to implement my own sort algorithm, though. For example, the
column contains data like:

<a href="http://www.example.com">DEF</a>
<a href="http://www.test.somedomain">ABC</a>

If I sort by the default algorithm, I get 'DEF' before 'ABC' because the
strings are compared up until they differ after 'www.'. What I would like
to do is somehow sort on the strings 'DEF' and 'ABC'. Is this possible?
Can I somehow implement a custom sort algorithm and then use it from a
DataGrid or DataView?
Nov 15 '05 #1
2 6477
Hi Mike,

My guess is that you could create a wrapper class for your HTML snippets
that would implement the IComparable interface and ensure the expected sort
order. This class should also override the ToString() method to return the
HTML snipper content, and it should have a constructor creating an instance
from a string passed as well as type conversion operators making it
interchangeable with the System.String class.

An easier solution could exist, but I cannot currently think of anything
simpler. Please treat this as an "off the top of my head" idea.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Mike Irwin" <mi**@faroutfreakyshit.com> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
I set up sorting by various columns for a DataGrid. For one of the columns, I would like to implement my own sort algorithm, though. For example, the
column contains data like:

<a href="http://www.example.com">DEF</a>
<a href="http://www.test.somedomain">ABC</a>

If I sort by the default algorithm, I get 'DEF' before 'ABC' because the
strings are compared up until they differ after 'www.'. What I would like
to do is somehow sort on the strings 'DEF' and 'ABC'. Is this possible?
Can I somehow implement a custom sort algorithm and then use it from a
DataGrid or DataView?


Nov 15 '05 #2

"Mike Irwin" <mi**@faroutfreakyshit.com> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
I set up sorting by various columns for a DataGrid. For one of the columns, I would like to implement my own sort algorithm, though. For example, the


Define an object, such as CompareObject, that implements the IComparer
interface. Put your comparison logic for two items to be compared in the
Compare() method.

Then to sort, in the main routine put the other objects to be sorted into an
array, such as ObjectArray, and use Array's Sort() method. Something like

System.Array.Sort(ObjectArray, // Array array
new CompareObject() // IComparer comparer
);

You can bind the sorted array to the DataGrid.

-- Alan
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chris Mayers | last post by:
I have a Windows Forms DataGrid that has a DataView as a datasource. My problem is that I want the datagrid to exhibit some special sorting properties when the header rows are clicked on. From...
2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
1
by: xrow | last post by:
Hello I have a simple webservice / c# application that receives data from server and prints the data in the asp:datagrid control I have problem when sorting data in datagrid I have created...
2
by: Ken Tucker | last post by:
I've read about this issue in many articles across the net... But haven't found a solution. I see all kinds of custom code to perform sorting with datagrids, but my example is so simple, I must...
7
by: DC Gringo | last post by:
I have a datagrid that won't sort. The event handler is firing and return label text, just not the sort. Here's my Sub Page_Load and Sub DataGrid1_SortCommand: -------------------- Private...
1
by: Jeremy | last post by:
I want my gird to sort only the items on the current page when I click on a column header. I wrote a little test app, but when I sort it pulls in items from other pages and places them on the current...
11
by: rkbnair | last post by:
I have created a datagrid in my aspx with the 'AllowSorting' property to true. When clicking on the column header, the page refreshes. However the sorting is not done. Am I missing anything? I...
4
by: G .Net | last post by:
Hi I have a question which I hope you can help with. I am setting the DataSource of a DataGrid to be a DataView. I am sorting the DataView by various fields which include a Date. When I...
6
by: Nick | last post by:
I have a code that returns data in IList. My webGrid doesn't allow me to sort with IList returned, it say it only suports DataView, DataTable and DataSet, not IEnumerable. I don't know how to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.