Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sorting an image column in a datagridview?

Posted on 2011-02-25
4
Medium Priority
?
159 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 1500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Screencast - Getting to Know the Pipeline
Suggested Courses

963 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