Results 1 to 16 of 16

Thread: [RESOLVED] ListView ItemSelectionChanged event issue

  1. #1

    Thread Starter
    Banned
    Join Date
    Sep 2024
    Posts
    10

    Resolved [RESOLVED] ListView ItemSelectionChanged event issue

    Hello all,

    I am again not going to post any code here because I know my issue is with my code that I have created, thus everything probably will have to be re-written. Here is my issue:

    I have a form with a listview control, some buttons and a menu bar. When the form loads, the user can select one of the menu bar options and open one of two types of word lists. After the words are displayed in the listview, some of the menu options are changed (either disabled or enabled) and the same happens to the buttons. This is all based upon what type of word list is opened (loaded). I might want to tell you that the shortest of the lists may contain a maximum of 6500 words. Currently I do not have ANY issue with loading the words very fast. No, I am not loading these words in virtual mode. I don't understand this.

    Now, when the user selects any single word - the buttons are to change state (disable / enable). The code for this function is not directly written into the listview event - it is called. What happens is that IF a user selects 1 word, the code that decides what buttons need to change runs once - great. Now if the user selects 1 word, then holds down the shift button and selects a word (ie: 155 lines down) then this code runs 155 times!

    My goal is to define what buttons need to be disabled or enabled based upon how many words are selected and the type of word list opened. I don't need this code to run each and every time a word is selected.

    I am also attempting to show the user how many words (ListView items) are selected in a label on this same form. This is also updated with each item selected. I would only like to show a total selected AFTER the last item is selected.

    Does anyone have any idea how I can improve the function of this "list editor"?

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

    Re: ListView ItemSelectionChanged event issue

    If the problem is with the code you have written then you need to show us that code so we can see what's wrong with it. You need to start by debugging that code to determine EXACTLY where and how its behaviour differs from what you expect.
    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
    Banned
    Join Date
    Sep 2024
    Posts
    10

    Re: ListView ItemSelectionChanged event issue

    Quote Originally Posted by jmcilhinney View Post
    If the problem is with the code you have written then you need to show us that code so we can see what's wrong with it. You need to start by debugging that code to determine EXACTLY where and how its behaviour differs from what you expect.
    jmcilhinney: Again, I will NOT post code here. I know what the issue is. In short:

    1) When a user selects an item, it runs the ItemSelectionChanged event.
    2) This calls my subroutine to adjust the status of the buttons and menus
    3) If the user selects more than 1 item, #2 keeps happening for each item selected

    I was hoping to solicit some idea how to:

    a) maybe get the total number of selected items AT THE ItemSelectionChanged event OR someplace else
    b) then I could simply say something like: "if this isn't the last item selected - ignore this call".

    I also suspect that I may be loading this listview wrong, but I do not understand how to do this otherwise.
    Posting code here would have confused you even more AND you would have had to do what is MY responsibility.
    I personally think that this would have been very rude to expect that kind of help.

  4. #4

    Thread Starter
    Banned
    Join Date
    Sep 2024
    Posts
    10

    Re: ListView ItemSelectionChanged event issue

    I have figured out a temporary solution. I added a label to the form that starts out hidden. When the user selects any item in the listview, the label is shown. In the click event of the label, I placed the call to the sub that determines which buttons and menus should be controllable.
    I was hoping to somehow "not" have to do this, but it works.

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

    Re: [RESOLVED] ListView ItemSelectionChanged event issue

    A ListView has a SelectedItems property, so it seems like that might be useful. There's also a SelectedIndices property, so it's hard to see how one or the other wouldn't provide what you need. We shouldn't really have to tell you what properties are available though, given that they are listed in the documentation and you should already have consulted that.
    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

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] ListView ItemSelectionChanged event issue

    I also suspect that I may be loading this listview wrong, but I do not understand how to do this otherwise.
    Gee, if only there were some way for us to see how you were doing that then we could tell you. I just can't think of any way to do that though.
    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

  7. #7

    Thread Starter
    Banned
    Join Date
    Sep 2024
    Posts
    10

    Re: [RESOLVED] ListView ItemSelectionChanged event issue

    Quote Originally Posted by jmcilhinney View Post
    A ListView has a SelectedItems property, so it seems like that might be useful. There's also a SelectedIndices property, so it's hard to see how one or the other wouldn't provide what you need. We shouldn't really have to tell you what properties are available though, given that they are listed in the documentation and you should already have consulted that.
    Again, this is what was happening. I was using EITHER the SelectedItems property OR the ItemSelectionChanged property.

    When a user selected an item, a subroutine (called within) would run. This happened EACH time a new item was selected. The code that was in this subroutine would determine which buttons and menu's to enable based upon the number of items selected AND the type of word list opened.

    If somehow a user manually selected 155 items (any amount), this code would run the same amount of times. I did not want this. I only wanted it to run 1 time AFTER all of the items were selected.

    I know that you guys know more than I do. I also know that I cannot expect to learn anything IF YOU write this code for me. Look, I am 65 years old and I am done with the games. I just want to have fun with this, learn a little and create something simple that works.

    I can see now how this forum is being run - you are damned if you do, and the same if you don't Give me a break, again it's not like I am asking YOU do do what YOU expect I should.

  8. #8
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,630

    Re: ListView ItemSelectionChanged event issue

    Quote Originally Posted by EReaUser2012 View Post
    I was hoping to solicit some idea how to:

    a) maybe get the total number of selected items AT THE ItemSelectionChanged event OR someplace else
    b) then I could simply say something like: "if this isn't the last item selected - ignore this call".
    With code. And I won't post code either.

  9. #9
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,630

    Re: [RESOLVED] ListView ItemSelectionChanged event issue

    Quote Originally Posted by EReaUser2012 View Post
    When a user selected an item, a subroutine (called within) would run. This happened EACH time a new item was selected. The code that was in this subroutine would determine which buttons and menu's to enable based upon the number of items selected AND the type of word list opened.

    If somehow a user manually selected 155 items (any amount), this code would run the same amount of times. I did not want this. I only wanted it to run 1 time AFTER all of the items were selected.
    Ok. Well, ask yourself this. Take code out of this. How is it possible to know when the user is done selecting items? I'll answer before your brain explodes - it isn't, unless a secondary action is taken by the user to indicate so, like clicking a "Done" button or something like that.

    That sounds like what you are doing with a Label as you indicated in an earlier post. A button would be a more conventional control to use for user interaction, but whatever works for you works for you.

  10. #10

    Thread Starter
    Banned
    Join Date
    Sep 2024
    Posts
    10

    Exclamation Re: [RESOLVED] ListView ItemSelectionChanged event issue

    Quote Originally Posted by OptionBase1 View Post
    Ok. Well, ask yourself this. Take code out of this. How is it possible to know when the user is done selecting items? I'll answer before your brain explodes - it isn't, unless a secondary action is taken by the user to indicate so, like clicking a "Done" button or something like that.

    That sounds like what you are doing with a Label as you indicated in an earlier post. A button would be a more conventional control to use for user interaction, but whatever works for you works for you.
    You are not getting the "last laugh". I had read that by loading the items into a listview a different way (maybe virtually) that I could have done things differently. Exactly how, I did not know. It was ideas I was looking for - or didn't you figure this out? Oh, btw - the difference between a button and a label is how it's drawn. Did you think that maybe I didn't want the extra border on my form, or just wanted a smoother appearance shown? Again you have shown your true colors. You want to push this "damned if you do and damned if you don't" way of coding. I say - bullshit. Do what you want with my GD account, post ****ing whatever.

  11. #11
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,630

    Re: [RESOLVED] ListView ItemSelectionChanged event issue

    Quote Originally Posted by EReaUser2012 View Post
    You are not getting the "last laugh". I had read that by loading the items into a listview a different way (maybe virtually) that I could have done things differently. Exactly how, I did not know. It was ideas I was looking for - or didn't you figure this out? Oh, btw - the difference between a button and a label is how it's drawn. Did you think that maybe I didn't want the extra border on my form, or just wanted a smoother appearance shown? Again you have shown your true colors. You want to push this "damned if you do and damned if you don't" way of coding. I say - bullshit. Do what you want with my GD account, post ****ing whatever.
    Neither of my posts referenced your issue of how you load your listview. As for the rest of your post, get a grip.

  12. #12

    Thread Starter
    Banned
    Join Date
    Sep 2024
    Posts
    10

    Exclamation Re: [RESOLVED] ListView ItemSelectionChanged event issue

    Quote Originally Posted by OptionBase1 View Post
    Neither of my posts referenced your issue of how you load your listview. As for the rest of your post, get a grip.
    You started this with your "Hollier than thou" attitude. Just because you manage this GD site does NOT make you better than anyone else that comes here.
    Last edited by jmcilhinney; Oct 20th, 2024 at 03:52 AM.

  13. #13
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,630

    Re: [RESOLVED] ListView ItemSelectionChanged event issue

    Quote Originally Posted by EReaUser2012 View Post
    You started this with your "Hollier than thou" attitude. Just because you manage this GD site does NOT make you better than anyone else that comes here.
    I have absolutely nothing to do with the management of this site in any way shape or form.

    You belligerently insisted from the very beginning of this thread, and then doubled down on it in subsequent replies, that you are refusing to post any code related to the issues you are experiencing. After that "introduction", all forum decorum bets are off IMO.

    Feel free to browse around other "civil" threads here and get an idea of how to create a new thread that will get you effective replies.

  14. #14

    Thread Starter
    Banned
    Join Date
    Sep 2024
    Posts
    10

    Re: [RESOLVED] ListView ItemSelectionChanged event issue

    No, I did NOT. This is what YOU interpreted. You FULLY understood my situation. I know that you did because you came back and acknowledged that I should use either property SelectedItemIndex or ItemSelectionChanged. You already knew I was using one of the two of these because I had explained that they kept getting run each time a user clicked (selected) an item in my ListView.

    All I wanted is some idea how I could write my code a different way to circumvent my issue. It wasn't necessary for ANYONE to write code for me. You yourself don't like to do this because you want people to understand what they are doing. This is a rather large program I am working on. This is MY work and nobody but me NEEDS TO WORRY about the issues I AM EXPERIENCING. The title for this particular site says Visual Studio .NET. This is what I am using - so this is where I posted my issue. Now for the third God Damn time - delete this ****ing account because you stupid Mother ****ers just don't understand or even want to.

  15. #15
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,630

    Re: [RESOLVED] ListView ItemSelectionChanged event issue

    Quote Originally Posted by EReaUser2012 View Post
    No, I did NOT. This is what YOU interpreted.
    First off, LOL.

    Your very first wording:

    Quote Originally Posted by EReaUser2012 View Post
    Hello all,

    I am again not going to post any code here
    First reply:

    Quote Originally Posted by EReaUser2012 View Post
    jmcilhinney: Again, I will NOT post code here.

    Now then.

    Quote Originally Posted by EReaUser2012 View Post
    You FULLY understood my situation. I know that you did because you came back and acknowledged that I should use either property SelectedItemIndex or ItemSelectionChanged. You already knew I was using one of the two of these because I had explained that they kept getting run each time a user clicked (selected) an item in my ListView.
    No idea what you are talking about, I never brought up anything related to any of those items. You do realize that I'm not jmc, right?

    Finally:

    Quote Originally Posted by EReaUser2012 View Post
    All I wanted is some idea how I could write my code a different way to circumvent my issue. It wasn't necessary for ANYONE to write code for me. You yourself don't like to do this because you want people to understand what they are doing. This is a rather large program I am working on. This is MY work and nobody but me NEEDS TO WORRY about the issues I AM EXPERIENCING. The title for this particular site says Visual Studio .NET. This is what I am using - so this is where I posted my issue. Now for the third God Damn time - delete this ****ing account because you stupid Mother ****ers just don't understand or even want to.
    Ok, so answer me this. How can we tell you how to write your code differently if you don't show us how you wrote your code to begin with? Again, I'll answer the question for you before your brain explodes - we can't.

    Have a wonderful, completely sane day.

  16. #16
    Administrator Steve R Jones's Avatar
    Join Date
    Apr 2012
    Location
    Clearwater, FL.
    Posts
    2,345

    Re: [RESOLVED] ListView ItemSelectionChanged event issue

    OH....we've had enough of this. Everyone needs to say BYE BYE

Tags for this Thread

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