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.somedo main">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? 2 6502
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**@faroutfre akyshit.com> wrote in message
news:uU******** ******@TK2MSFTN GP10.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.somedo main">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?
"Mike Irwin" <mi**@faroutfre akyshit.com> wrote in message
news:uU******** ******@TK2MSFTN GP10.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.So rt(ObjectArray, // Array array
new CompareObject() // IComparer comparer
);
You can bind the sorted array to the DataGrid.
-- Alan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 reading round the newsgroups, it seems that a custom 'IComparer' is the
answer, but I'm not quite sure how to do this. Really, how to get at the
IComparer that the DataGrid/DataView uses for sorting.
Can anyone point me towards a nice example...
|
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 datagrid.
HTML
Datagrid1
TemplateColumn
Table
Header information
Detail Information
|
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 SortCommand event in my .aspx file for my datagrid DataGrid2 but I am not able to access my datarecord nor dataset from my SortCommand event. I recieve also an error when running with created event if don't change event method declaration to public void...
|
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 just be missing something.
Basically, I have a .aspx page that is very simple and has a simple
datagrid. All code is in the .cs page for the datagrid (hence, I'm doing all
datagrid work programmatically). The datagrid is populated from a SQL table...
|
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 Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
| |
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 page.
i.e.
If I have:
IntegerValue StringValue CurrencyValue
0 Item 0 0
1 Item 1 1.23
|
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 populate the data if !postback.
|
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 create a new row in the DataGrid and set the date to me within the
current sort range, the newly created row "jumps" to its correct position in
the grid. This obviously makes sense because it is following the sort rule.
|
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 return the DataSet type when
using the following code:
======== this is my interface ======================
namespace WareHouse.DataLayer.DataObjects
{
/// <summary>
/// Defines methods to access categories and products.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |