VS 2008 : Sort Columns In Listview?
Apr 16, 2009
I'm trying to set something up where the user can sort each column by clicking on the header... i've looked at some other examples and they seem pretty longwinded..so far i have the below...
VB
Private Sub resultsListView_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles resultsListView.ColumnClick
Dim oldsort As SortOrder
[code]....
which works fine... but only for the first column in the list view.Is there a way of specifying which column to sort based on which is clicked?
View 8 Replies
ADVERTISEMENT
Apr 16, 2012
Using Microsoft Visual Studio 2010 Ultimate - VB.Net
I'm writing an application where as many of other applications fulfill the requirements to be as an app , having it's statistics schema. Thus I made a form where I have a combox(of query category), a textbox(as searchfield), two datetimepickers(from and to) a listview and a button to fire the event with functions in it. I'm all set except for a minor issue I've encountered during my very first experiments with ListView control. Thus far I didn't know that VB users are stuck with that control's property options (whereas DataGridView has way too many), especially when it came to Column reordering/s. With the simple but not satisfying property Sort I couldn't find a proper solution to my issue.
when I click on of the columns in the listview to do a Number/Date/Text reordering (descending>ascending, via-verse). Not to forget to mention there a limited number of columns most likely 2-4 max.
The listview control has lvResults name and has for now columns inserted as "Country" and the other for subitems "Total Spent".
One e.g. of the values inserted to it is like this :
[Code].....
If pressed on Total Spent, should reorder from highest to the lowest number and via-versa. If pressed on Country should reorder from A to Z or via-versa.
View 3 Replies
Mar 26, 2009
How do I sort a DGV by 2 columns? The DGV is not bound.
View 4 Replies
Jun 21, 2011
After a long time searching, I am still facing an issue with my listview column header I am trying to add a sort indicator (a small 16x16 arrow, next to the column title - looks quite good).
- My listview is in Ownerdraw mode for : Items & Subitems for a couple of reasons
- So far, I was letting the system do the job for the header (e.drawdefault = true)
I managed to add very easily the arrow using the e.graphics class, right after the e.drawdefault=true, and it is actually working good.
print01.gif
(Sub ColumnHeader OwnerDraw)
e.DrawDefault = True
e.Graphics.DrawImage(My.Resources.fleche_v2_16x16, 34, 2, 16, 16)
As you can see, I'm simply using a resource, and am forcing it to 16x16 with a custom location x=34 pixels y=2pixels My issue comes with the following :
(Sub ColumnHeader OwnerDraw)
e.DrawDefault = True
e.Graphics.DrawImage(My.Resources.fleche_v2_16x16, (e.Bounds.X + 34), 2, 16, 16)
The arrow wont draw Of course the sort indicator will sometime be on the 2nd column etc.. That's why I need to use the column header's bounds.I can already hear you saying : if you do not owner draw, you can't..But why is it working with a static location (, 34, 2, 16, 16) ans not starting from another static location (e.bounds.x) How can I fix that ? I cant find previous issues similar to that one over the internet.
Points of interest :
- I tryed to load the int value e.bounds.x into a variable before, using that instead of e.bounds.x but it's all the same.
- Using the imagelist is not an option, As you can tell from the screenshot, I am already using images for headers.. the sort indicator is coming as another image
- Using ">" or "<" in the header's text is not an option either........ (sorry pal It does not look good at all..)
- Drawing the header totally in owner draw mode would be an option, but it looks quite hard to do (need to manage the "rounded" header style of the system, the mouse over - small yellow line rounded on the sides in WinXp, the click effect....).
View 11 Replies
Mar 13, 2009
I am currently using a recursive search to get all of the files in a directory as well as in all subdirectories of that directory. At the moment (as a temporary solution to make sure the script worked) I have all files with their respective directories listed in a listview (2 separate columns).
View 3 Replies
Apr 22, 2011
I need to loop inside listview and its columns Sub Items. I'm currently using this.
For Each item As ListViewItem In ListView1.Items
For Each si As ListViewItem.ListViewSubItem In item.SubItems
Next
Next
But it over loops on the items causing the code to produce incorrect tasks.
View 4 Replies
Jun 22, 2010
im trying to make the listview sort the listview items by column (whichever column was clicked, sort the list based on that column)
in vb6 it was done by:
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
Static olditem&
With ListView1
[Code].....
View 2 Replies
Dec 10, 2009
I'm sure this has been asked here before but i couldn't find it, anyway my issue is i have filled a dgv using a LINQ query and i need to sort my results by 2 columns, i.e. type and cost so that it lists items by each type in creasing cost[code]...
View 10 Replies
Sep 1, 2011
I currently have a datagridview that is built from a datatable So lets say we have 6 columns
A B C D E G
So the users will select there data from another program and paste into the the table. So lets assume that the data that is pasted is; (the column names are automatically put in)
A B C D E G
123 456 789 101 112 134
So the table will now look like following (I remove the first row because its the same as the column name)
A B C D E G
A B C D E G
123 456 789 101 112 134
My problem is that the users can rearrange thier tables(column index) so lets say user A has the table in this format
A B D E C G
123 456 101 112 789 134
So when they paste into the program, it will look like
A B C D E G
A B D E C G
123 456 101 112 789 134
So now "C" "D" "E" are incorrect and i need to swap those columns to be the same as the column name. I'm not sure how to attack this problem.My thoughts were to paste the data as is, than see what the first row in each column equals.so if it equals "A" assign it an index 0
B 1
C 2
This seems theres too many steps and will slow down the app...
View 2 Replies
Nov 30, 2009
How do i sort a datagridview by several columns?
I want to sort the data in my DataGridView by the Title, Location and Reference, i have the following to sort the DGV by title, how can i include the two other columns in the sort?[code]...
View 11 Replies
May 26, 2012
how would you sort out two columns so when you click them, it either sorts the listed items in Ascending/Descending order. I have named Name column to colName and Mobile column to colMobile
View 10 Replies
Feb 15, 2009
I would like to know if it is possible if the columns of the listview can be resized automatically based on the information in the listview?
View 4 Replies
Apr 12, 2012
Currently my ListView sorts items by image.index. So 0 is at the top, then 1, 2 and so on. Think of it as an IRC chat room nick list. Ops at top then the rest are sorted alphabetically
[Code]....
View 18 Replies
Jun 24, 2011
How can I set up my WPF datagrid to sort on multiple columns similar to having two sortable columns, clicking on the header of the first column for a primary sort and then SHIFT clicking on the header of the second column for a secondary sort. I would like the multiple column sort to happen automatically when the user clicks on the header of the first column without having to SHIFT click on the second column header. Is there a way to do this entirely in the xaml? If not how can I do this in the code behind? Currently using VB.Net but a C# snippet is acceptable if you have one.
View 2 Replies
Jul 19, 2011
How do I sort a DGV by multiple columns.
View 1 Replies
Jul 25, 2011
I am trying to program my page in vb.net and asp.net so that when a user clicks on a column heading of a gridview, the data is sorted either in ascending or descending order. note that my data is coming from an SQL Server Express database. So far, I have done it so that the gridview can be sorted:
[Code]...
View 2 Replies
Mar 23, 2012
I fought through a good amount of this and have gotten to the point where I can sort my arrays. What I need to do now is take the following code and sort the elements in descending order instead of ascending order. I don't know how to do that with the two arguments in the code:
Dim Cols(3) As Int16
Cols(0) = ColumnNumber + 1
Cols(1) = ColumnNumber + 2
Cols(2) = ColumnNumber + 3
[Code].....
View 1 Replies
Jun 22, 2010
how do you sort the data by columns in a list view, for example, clicking the title of the column to sort by ascending order.
View 3 Replies
Feb 4, 2011
I have a datagridview with its datasource binded to a List(Of T). Now i would like to sort on any of the columns.My code:
'Database access : items = List(BlogPost)
dgBlogPosts.DataSource = items
'My BlogPost Class
Public Class BlogPost
[Code]...
View 1 Replies
Jun 17, 2010
I've got a number of columns the user can sort by (Name, County, Active) and that's easy but messy. Looks something like this...
Select Case e.SortExpression
Case "Name"
If (isDescending) Then
[CODE]...
What I would LIKE to do, is something more ... like this
Private Function SortThatList(ByVal listOfStuff As List(Of Stuff), ByVal isDescending As Boolean, ByVal expression As Func(Of Stuff)) As List(Of Stuff)
If (isDescending) Then
[CODE]...
But it doesn't like the datatype (Of TKey) ... I've tired Func(Of stuff, boolean) (got something in c# that works nicely like that) but can't seem to get this one to do what I want.What's the magic syntax?
View 2 Replies
Jan 11, 2009
I have a listview that I want to sort from A-Z, but I also wan't to have it sorted in three seperate sections. Like say you have a list of users.
[Code]...
View 9 Replies
Apr 26, 2010
I'm trying to sort a ListView and have it working.. but was trying something.. and was curious why it doesn't appear to work..
In a gridview, the sorting event you can do a
With CType(sender, GridView)
.DataSource = Os
.DataBind()
End With
[Code].....
View 1 Replies
Dec 20, 2009
is this possible To loop through the column one entrys and then rearrange by there values?
example all column one is date entrys
12-11-08
12-07-08
and so on and reshuffle the listview?
View 3 Replies
Dec 16, 2009
I need the listview in my app to sort by the date (descending) in the second column after adding a new entry to it from another form. I have tried some column sorting examples made for the column click event but am not able to use those examples for what I'm doing as I keep getting error
View 17 Replies
Jun 22, 2010
im currently using vs.net 2003 my problem is that i want to sort items in listview by date (mm dd, yyyy) format and sort by a button not in the column :?:
View 2 Replies
Jun 18, 2011
I'm using the following code to sort a listview:It triggers off the column click envent.What I would like to add to my code is to manually trigger it in the code. My code enumerates all installed apps on a PC and places them into a listview. I then want to sort the listview as the next step in my code but the sort code from the MS site looks for the column which was clicked:
Private Sub lvVisualResults_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles lvVisualResults.ColumnClick
' Determine if the clicked column is already the column that is
[code]......
View 6 Replies
Jan 9, 2009
I'm trying to sort my listview using a custom icomparer. I have to sort numbers, strings, dates, and currency.
Here's the code to sort:
compareResult = ObjectCompare.Compare(listviewX.SubItems(ColumnToSort).Text, listviewY.SubItems(ColumnToSort).Text)
The problem is it sorts numbers wrong, such as:
10
2
3
instead of
2
3
10
View 3 Replies
Mar 7, 2011
I want to just sort one column in a listview control. Is this possible or are all the columns tied together?
View 2 Replies
Aug 2, 2010
I support a .Net 2.0 Windows application that has a custom listview control to allow for greater flexibility. I am not allowed to bring this to a newer version of the gramework until next year. We are moving from XP to Windows 7, and we have identified an issue with how the column sort image (up/down arrow) is drawn to the listview. Currently in XP, the image is drawn to the right of the column's text. However, in Windows 7, I am getting Access Violation Exceptions. Now, I know that the error is with the improper handling of memory using the unmanaged code as shown below. I am looking for a method to mimic what we have below in a safe manner using managed code.
[Code]...
View 1 Replies
Oct 15, 2009
I'm using VB 2008 and windows vista. I'm using a listview in my application.(view=details) I assign an image list to listview.smallimagelist. when user try to sort the listview by clicking the column header i use the imageindex property to set an icon for that column header, this works fine. When user clicks another column to sort the listview by that, I use listview.columns(PreviousColumnIndex).imageindex=-1 to remove the sort order icon from the previously selected columnheader, but it does not remove the picture from the previous columnheader. How should I remove the icon(picture) from the previous column header?
View 7 Replies