Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sorting an image column in a datagridview?

Posted on 2011-02-25
4
Medium Priority
?
158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

721 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