Solved

Sorting an image column in a datagridview?

Posted on 2011-02-25
4
150 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 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

12 Experts available now in Live!

Get 1:1 Help Now