Sort a column in List view
Sort a column in List view
Sort a column in List view
Sort a column in List view
Sort a column in List view
Sort a column in List view Sort a column in List view Sort a column in List view Sort a column in List view Sort a column in List view Sort a column in List view Sort a column in List view Sort a column in List view
Sort a column in List view Sort a column in List view
Sort a column in List view
Go Back  Xtreme Visual Basic Talk > > > Sort a column in List view


Reply
 
Thread Tools Display Modes
  #1  
Old 11-24-2016, 10:27 AM
hchain's Avatar
hchain hchain is offline
Junior Contributor
 
Join Date: Aug 2003
Location: Houston, Texas
Posts: 239
Default Sort a column in List view


I have sub to sort a list view by column:
Sub lvContact_ColumnCLick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)

How can I call it?
I tried different things, in particular:
Call lvContact_ColumnCLick("Column_Name")
but I get an Type Mismatch error...

Thanks!
__________________
I would have written you a shorter letter, but I did not have the time.
Blaise Pascal
Reply With Quote
  #2  
Old 11-25-2016, 02:33 AM
Goggy's Avatar
Goggy Goggy is offline
Contributor
 
Join Date: Sep 2005
Location: Enschede,The Netherlands
Posts: 649
Default

Quote:
Sub lvContact_ColumnCLick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
Quote:
Call lvContact_ColumnCLick("Column_Name")
The Sub wants a "MSComctlLib.ColumnHeader" type as parameter, but your passing a string value, so that's not going to work.
__________________
As finishing touch, god created the Dutch!

utterly useless, but always trying to help
Reply With Quote
  #3  
Old 12-03-2016, 03:24 PM
hchain's Avatar
hchain hchain is offline
Junior Contributor
 
Join Date: Aug 2003
Location: Houston, Texas
Posts: 239
Default

I understand that, but I do not know how to do it :-)
__________________
I would have written you a shorter letter, but I did not have the time.
Blaise Pascal
Reply With Quote
  #4  
Old 12-03-2016, 09:07 PM
Cerian Knight's Avatar
Cerian KnightSort a column in List view Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,184
Default

The sub is called by clicking on a column header (that is only visible when .View = lvwReport). Does the sub fire for you when you click a column header? I avoid calling events directly, but often have events call my own subs to share code.

If you need to manually call the sub (e.g. not only triggered by column header click), why not have the lvContact_ColumnClick sub code call another sub that that you can call manually (passing a column name)?

If that doesn't help, to be clear, the question you are asking is akin to Q: 'Why can't I call a button click event'? A: Why not just click the button? You'll have to explain better why you need to do this (and show us what else you have tried, after digesting the above information).
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #5  
Old 12-04-2016, 03:24 PM
Cerian Knight's Avatar
Cerian KnightSort a column in List view Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,184
Default

With the above out of the way, here is a manual call example:
Code:
Dim lvColHead As MSComctlLib.ColumnHeader
Set lvColHead = ListView1.ColumnHeaders(1) 'first column
ListView1_ColumnClick lvColHead 'manually call click event
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #6  
Old 12-04-2016, 05:16 PM
hchain's Avatar
hchain hchain is offline
Junior Contributor
 
Join Date: Aug 2003
Location: Houston, Texas
Posts: 239
Default

Thanks a lot, Cerian, this works perfectly for me.
To answer your question, I want the listview to open already sorted on a given column.
That column depends on where the listview is called from (so I can't use the Sorted property of the listview because I don't know which column upfront). For instance, I may want the listview to open sorted on the City one time, but sorted on the Annual_Sales another time.
Note that the user can then sort to his heart content later by clicking on the headers, but the listview is already sorted on the relevant criteria when it opens.
In any case, thanks a lot!
__________________
I would have written you a shorter letter, but I did not have the time.
Blaise Pascal
Reply With Quote
  #7  
Old 12-06-2016, 08:22 AM
Hugh Lerwill Hugh Lerwill is offline
Junior Contributor
 
Join Date: Oct 2004
Posts: 293
Default

>...I want the listview to open already sorted on a given column...I may want the listview to open sorted on the City one time, but sorted on the Annual_Sales another time.

Is'nt that just a matter of setting lv.SortKey to the appropriate lv.ColumnHeader.index - 1 when the ListView is opened.
Reply With Quote
Reply

Tags
call, column, list, sort, view


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Sort a column in List view
Sort a column in List view
Sort a column in List view Sort a column in List view
Sort a column in List view
Sort a column in List view
Sort a column in List view Sort a column in List view Sort a column in List view Sort a column in List view Sort a column in List view Sort a column in List view Sort a column in List view
Sort a column in List view
Sort a column in List view
 
Sort a column in List view
Sort a column in List view
 
-->