Results 1 to 17 of 17

Thread: Show selected Column (Listview)

  1. #1

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Show selected Column (Listview)

    I have a listview with approx 20 columns, 4 of which are dates.

    When I scroll along to one of these dates columns, and click on the columnheader to sort that column, I clear the listbox and reload in the sort order by recalling the data from the database via a recordset.

    The problem is, although the data is sorted as I want, the column that has the sort on it is now not showing. I have to scroll back along to show it.

    How can I set it so that the column that has the sort on it is visible?
    I looked for an 'EnsureVisible' property, but either I have missed it somehow, or that isn't the way to go.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  2. #2
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Show selected Column (Listview)

    aikido..

    What about a Refresh?

    ListView1.refresh

    since you have sorted the DB, records may reloaed in the latest order in to the list view

  3. #3

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Show selected Column (Listview)

    No, this doesn't work Fazi. It is still sorted, but the sorted column still doesn't show without scrolling to it!
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  4. #4
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Show selected Column (Listview)

    How about using the Position Property to move the column to the first position:


    VB Code:
    1. Private Sub Command1_Click()
    2.     ListView1.ColumnHeaders.Item(3).Position = 1
    3. End Sub
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Show selected Column (Listview)

    I would like to try to keep all of the columns in the same place as they work across in a specific order, which is relevent else where.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  6. #6
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Show selected Column (Listview)

    Quote Originally Posted by aikidokid
    I would like to try to keep all of the columns in the same place as they work across in a specific order, which is relevent else where.

    Hmm, I am not sure how you could do then, sorry
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  7. #7

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Show selected Column (Listview)

    Ok, thanks anyway Mark and Fazi, I will keep looking
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  8. #8

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Show selected Column (Listview)

    I have been looking at MSDN here and more specifically here

    I have tried using this but I get the error message:

    Run-time-error '438': Property doesn't support this method

    Code:
    lresult = SendMessage(lvwShowAll, LVM_SETSELECTEDCOLUMN, 12, 0)
    I just wondered what I have wrong with this code, and secondly, is this something that would achieve what I am after?
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Show selected Column (Listview)

    Is lvwShowAll a control or the hWnd of a control? (I don't think the default property of a listview is its hWnd.) SendMessage wants an hWnd as the first parameter.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  10. #10

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Show selected Column (Listview)

    Quote Originally Posted by Al42
    Is lvwShowAll a control or the hWnd of a control? (I don't think the default property of a listview is its hWnd.) SendMessage wants an hWnd as the first parameter.
    OOPS, that was a bit obvious

    I have tried this and it runs, but either I don't know how to correctly use it or it doesn't do what I am after, which is to make sure a ceretain column is showing after reloading the listview from a recordset, loaded by date order.

    Any ideas?
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  11. #11
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Show selected Column (Listview)

    akido,

    check this link as well. http://vbnet.mvps.org/code/comctl/lvmembers.htm
    it has tons of messages that you can send to a listview .

  12. #12

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Show selected Column (Listview)

    Thanks Fazi. I have bookmarked that site

    I have changed my code to

    Code:
    SendMessage lvwShowAll.hWnd, LVM_SETSELECTEDCOLUMN, ColumnHeader.Index - 1, 0
    but this still does not work..

    From what I have read and found out so far, this is the message I need, so am I using it incorrectly?

    Quote Originally Posted by Microsoft Forum
    How does the ListView know which column is used for sorting?
    LVM_SETSELECTEDCOLUMN
    Last edited by aikidokid; Jun 28th, 2007 at 10:43 AM.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  13. #13

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Show selected Column (Listview)

    I now have this, but LVM_SETSELECTEDCOLUMN is showing a value of "Empty" and I don't know why!

    vb Code:
    1. If ColumnHeader.Index - 1 = 12 Then
    2.         SendMessage lvwShowAll.hWnd, LVM_SETSELECTEDCOLUMN, ColumnHeader.Index - 1, 0
    3.     End If
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  14. #14
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Show selected Column (Listview)

    Any thig to do with the below

    LVM_SETSELECTEDCOLUMN Message

    MSDN :
    Note: To use this API, you must provide a manifest specifying Comclt32.dll version 6.0.


  15. #15

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Show selected Column (Listview)

    Thanks Fazi, I have actually been looking at this here.

    I have to be honest, this seems a bit too advanced for me.
    I have never used manifest files.

    I don't have a lot of experience using 'SendMessage' apart from code that people have helped me with!
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  16. #16
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Show selected Column (Listview)

    to apply XP visual style to listviews, you need to use microsoft windows common controlls 5.0 sp2. then applying XP style is very simple. tons of articles and manifiest files are on the net.

    dont warry.

  17. #17

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Show selected Column (Listview)

    What is the difference between Windows common controls 5.0 SP2
    and what I am using which is Windows common controls 6.0 SP6
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width