Results 1 to 5 of 5

Thread: [RESOLVED] Help with a ListView Control

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2024
    Posts
    3

    Resolved [RESOLVED] Help with a ListView Control

    Hello,

    I am not going to post any code here because my issue isn't with how my code works. I have a form that has a listview control on it that gets populated with words. On the same form, I have a button that allows a user the opportunity to select (highlight) special words contained in the listview. Examples: all of the words starting with "g", all of the words with 5 consonants, all of the words ending in the letter "e"

    My code for this works flawlessly. After the code has finished highlighting the words, the form refreshes (focus has been removed and restored) and the listview redraws. This causes the first item in the listview to become "selected" or drawn with a square around it - even if it isn't a selected item! I find this distracting and annoying. Has anyone else had this issue? If so can you please share what you have done to overcome this?

    Again I am using VS 2012 (it was free and I cannot afford anything else right now)

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,691

    Re: Help with a ListView Control

    A ListView can have multiple selected items but only one focused item and the two are independent of each other. If you're seeing a focus rectangle around an item it means that the ListView has focus and that is the FocusedItem. You need to either remove focus from the control or the item. You can call Select on another control or assign another control to the ActiveControl property of the form to shift focus, or you can set the ActiveControl to Nothing for no control to have focus. If you want the ListView to retain focus, I think that you can set the FocusedItem to Nothing to remove that focus rectangle.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2024
    Posts
    3

    Thumbs up Re: Help with a ListView Control

    Quote Originally Posted by jmcilhinney View Post
    A ListView can have multiple selected items but only one focused item and the two are independent of each other. If you're seeing a focus rectangle around an item it means that the ListView has focus and that is the FocusedItem. You need to either remove focus from the control or the item. You can call Select on another control or assign another control to the ActiveControl property of the form to shift focus, or you can set the ActiveControl to Nothing for no control to have focus. If you want the ListView to retain focus, I think that you can set the FocusedItem to Nothing to remove that focus rectangle.
    Thank you so very much. I will try this. You must remember that if "you" choose to see all of the items selected in a ListView, you must set the ListView to focused. If you do not, none of the selected items will be blue in color. This is what I do immediately after selecting any of the items (words). You are so sincerely appreciated.

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2024
    Posts
    3

    Re: Help with a ListView Control

    Quote Originally Posted by EReaUser2012 View Post
    Thank you so very much. I will try this. You must remember that if "you" choose to see all of the items selected in a ListView, you must set the ListView to focused. If you do not, none of the selected items will be blue in color. This is what I do immediately after selecting any of the items (words). You are so sincerely appreciated.
    jmcilhinney , This works wonderfully!!! It was as easy as telling the listview that the index 0 was not focused. Now I understand what the difference is. You did an excellent job of explaining, you were caring and totally professional.
    Thank you ever so much again. If you only knew how many hours I spent changing multiple forms and code to try to understand what was going on. I do not know how to close this issue but it CAN be closed now. YOU ROCK!!!

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,691

    Re: [RESOLVED] Help with a ListView Control

    You can still see the selection in a ListView that doesn't have focus if the HideSelection property is set to False. The colour used to highlight selected items will be less bold when the control doesn't have focus but it will still be visible.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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