Solved

Sorting an image column in a datagridview?

Posted on 2011-02-25
4
152 Views
Last Modified: 2014-04-10
Hey guys.  I have the code listed below to init a datagridview to some dummy data (for testing).  I want the user to be able to sort on the image column, but right now when you click the column header nothing happens.  What do I need to do?  I've read up on this but I'm still missing the solution.


Dim row As Object() = New Object() {TestApp.My.Resources.Resources.light_gray, "1", "1000"}
        DataGridView1.Rows.Add(row)

        row = New Object() {TestApp.My.Resources.Resources.light_gray, "1", "1000"}
        DataGridView1.Rows.Add(row)

        row = New Object() {TestApp.My.Resources.Resources.light_green, "2", "2000"}
        DataGridView1.Rows.Add(row)

        row = New Object() {TestApp.My.Resources.Resources.light_gray, "3", "3000"}
        DataGridView1.Rows.Add(row)

        row = New Object() {TestApp.My.Resources.Resources.light_red, "4", "4000"}

Open in new window

0
Comment
Question by:JasonWilliam
  • 2
  • 2
4 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 34982141
An image is simply a byte array, there is not real way to "sort" an image when compared to another image. What you will need to do is have a column in your datasource that determines the order you want the images "sorted" in when the column is click and set that column as the SortExpression for the column.
0
 

Author Comment

by:JasonWilliam
ID: 34982203
Hmm ok.  So lets say I add a fourth hidden column, and change my code as shown below.  Can you give me example code on how I would go about your suggestion?


Dim row As Object() = New Object() {1, TestApp.My.Resources.Resources.light_gray, "1", "1000"}
        DataGridView1.Rows.Add(row)

        row = New Object() {1, TestApp.My.Resources.Resources.light_gray, "1", "1000"}
        DataGridView1.Rows.Add(row)

        row = New Object() {2, TestApp.My.Resources.Resources.light_green, "2", "2000"}
        DataGridView1.Rows.Add(row)

        row = New Object() {1, TestApp.My.Resources.Resources.light_gray, "3", "3000"}
        DataGridView1.Rows.Add(row)

        row = New Object() {3, TestApp.My.Resources.Resources.light_red, "4", "4000"}

Open in new window

0
 
LVL 28

Accepted Solution

by:
strickdd earned 500 total points
ID: 34982437
If you want integrated sorting on the GridView, you will need to bind to some sort of asp:*DataSource object. I would recommend the asp:ObjectDataSource in your case. This can have the SELECT method point to a user defined class that returns a data table with your rows in it. Then all you need to do is enable sorting on the GridView and set the SortExpression to be the new column.
0
 

Author Comment

by:JasonWilliam
ID: 35012837
Ok... after playing around some I need to keep the data unbound.  

Any further suggestions?
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question