Solved

Sorting an image column in a datagridview?

Posted on 2011-02-25
4
149 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Ok... after playing around some I need to keep the data unbound.  

Any further suggestions?
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now