What can prevent a listbox item to be selected?

What can prevent a listbox item to be selected?
https://stackoverflow.com/questions/39213803/what-can-prevent-a-listbox-item-to-be-selected

Comments

  1. If you disable MultiSelect, does it work as expected in the large app?
     How about:
        SomeListBox.SetFocus;

    ReplyDelete
  2. When lots of edit controls lose focus, the selections are hidden. TListView has a HideSelection property that when set to False will leave the selections visible. TListBox doesn't seem to have it, but it may be hidden and accessible through an inherited class.

    ReplyDelete
  3. If I posted my reply above on SO, it would probably get flagged or deleted. I don't answer stuff on SO much any more because I'm tired of the overbearing nature some folks have towards some mythical sense of "purity" that SO supposedly aspires to.

    ReplyDelete
  4. David Schwartz Just curious: why would that reply be flagged or deleted?

    ReplyDelete
  5. I'm guessing because it doesn't directly answer the question. Half the time I don't know why things get flagged or deleted on SO, they just happen with no explanation. You're expected to read their minds. I tend to disagree with several of their policies, so I just prefer to stay away.

    ReplyDelete
  6. OK, my mistake. I had sworn to never ask or answer a question on StackOverflow again. I'm going to delete it when I'm back at my computer. It's become pointless to ask anything there. Or maybe I've become to stupid to ask questions in the right way. Maybe old age?

    ReplyDelete
  7. Bill Meyer I've tried SetFocus, didn't make a difference. Setting multiselect to false? Won't solve the problem, because I want multiselect, but might be worth trying anyway to get some more data to work with.

    ReplyDelete
  8. Especially since some people think SO is the ONLY place you'd ever want to post anything. Sorry. It's not worth the hassle. I can't tell you how many interesting questions I've seen posted that get slammed with flags and comments from holier-than-though thought police that eventually end up causing the thread to be locked. I think, "Thank goodness, the thread is locked, so no more of these psychotic faux law-enforcement types can post any more crap!" They need a policy that says, If you don't have anything good or useful to say, then don't. And ESPECIALLY if you think it's a dumb or poorly-asked question.

    ReplyDelete
  9. It's so pointless to tell me in the comments that the code works if pasted into a new VCL program. That's what I already wrote in the question, didn't I? It's also pointless to tell me that I should provide a minimal example for the problem. If I could do that I wouldn't have to ask, because I'd already know what causes the problem. But again, my mistake, I should have known that this are the kind of comments a question like this would draw on SO.
    So, what's the alternative? G+ isn't really suited for this kind of question. It starts with not allowing formatted text and doesn't end there. Maybe I should go back to the Embarcadero forums. Unfortunately they are technologically very much inferior to SO.

    ReplyDelete
  10. David Schwartz but in that case changing the focus back to the control (using tab) will make the selection reappear. This doesn't happen in my case. The item still has just a focus rectangle and gets selected only after I press space.

    ReplyDelete
  11. Come to think about it, I rarely use TListBox controls, preferring TListView because of so many strange limitations like this. These are inconsistencies that have never been corrected since Delphi was first released. And it's also why I tend to use Raize Components whenever I can -- they're far more consistent.

    ReplyDelete
  12. I have now deleted the question on SO. Thanks to those who tried to help me out.
    Btw: This was about the Uses Clause Manager dialog in GExperts.
    I have some ideas about what to try to track down the problem and will probably blog about it if I ever find out.

    ReplyDelete
  13. Yup, that's what happens to an awful lot of otherwise perfectly legitimate questions on SO ... the authors are bullied into deleting them.

    ReplyDelete
  14. Attila Kovacs actually no, most of the lines are simple add-calls to fill the list view. I only tried to explicitly call SetFocus once.

    ReplyDelete
  15. Thomas Mueller
    That was my thought, simply to get a clue what mechanisms are in play.

    ReplyDelete
  16. Problem is that SO is not forum. It is not for discussion, but for providing answers to specific questions with clear problem statement.

    Your question does not have MCVE. If we cannot reproduce your problem then we cannot answer it. The only way your question may get answered is that someone by pure luck experienced your issue and knows how to deal with it.

    So, why not allow such questions like yours, because it cannot hurt to have it there, and if gets answered even better.

    Problem is that if questions like yours are allowed (when we know (because we know you) that you have done what you could in trying to locate the issue, but you had no luck) then you allow million of horrible questions like following one:

    "What is the cause of 'Access violation at address 40105D94 in module ‘vcl60.bpl’. Read of address 09317AD0'

    I have a Delphi6 program which use multiprocess、multiThread ...

    When the program is running, it may happen Access violation coincidentally, then I restart it, the mistake disapper.

    What are the reasons for this problem ?

    Or is there any learning materials about vcl60.bpl"

    While your question is inevitably way better than the one I posted as example, basically both are questions about problems where community have to guess to find solution.

    Again, what is the problem with guessing?

    Problem with that is that when you are searching for solutions you have to go through all kinds of crap (both questions and answers) to find solution to a problem. And the more crap there is the more time you spend on wild goose chase.

    And I know that as user who actively uses SO for finding solutions to issues in technologies I am less expert than I am with Delphi and/or Windows.

    So, actually, it is in everyone's best interest to keep SO as clean as possible, even though sometimes questions we would like to ask and answer are not suitable there.

    ReplyDelete
  17. David Schwartz You would guess right. answer that does not answer the question would get deleted.

    Again, because with time people will upvote just about anything. So eventually, when you are searching for solutions and you find old question with plenty of answers you have to go through all kind of wrong and unhelpful answers just to find the real solution (if you are lucky)

    ReplyDelete
  18. Dalija Prasnikar Perhaps I'm naive but I'd try to solve the "crap" problem by downvoting. SO used to be more fun (for me as an answerer) when the rules (and mods) were more relaxed. Most of the brilliantly precise questions and super-smart answers will be obsolete pretty soon, anyway. Just my 2c, I don't care so much about it.

    ReplyDelete
  19. Attila Kovacs Sorry! ;-) I believe you can mute this thread.

    ReplyDelete
  20. Attila Kovacs​ ;-) You're welcome to share your opinions, too. Ah, you did already. ;-) OK, I shut up already (regarding SO).

    ReplyDelete
  21. FWIW, I would not set .Sorted := True until after I'd filled the box. No biggie for small lists, but it could slow down filling larger lists.

    ReplyDelete
  22. I'll have to check the code, but I think sorted is originally already set in the object editor and not changed at all.

    ReplyDelete
  23. Attila Kovacs I tried .ClearSelection. Didn't make a difference. Begin/EndUpdate was in the original code, but it doesn't make any difference if I add it to the test code now.

    ReplyDelete
  24. David Schwartz Sorted is set in the object inspector. I specifically contrived the example so sorted doesn't make a difference. The original code used IndexOf to get the index of the item to select.

    ReplyDelete
  25. Bill Meyer regarding disabling Multiselect: Yes, it works as expected then. One more data point.

    ReplyDelete
  26. Thomas Mueller Interesting. I assume you have explored the myriad properties in the Object Inspector. My guess would be that there is yet another setting somewhere....

    ReplyDelete
  27. Bill Meyer There are other list boxes on the form where selecting an item works. I have just compared the settings of one of those with the liistbox in question: They are identical.
    I have now re-enabled everything in the dialog I had disabled for my research. It still comes down to: It works with MultiSelect=false, doesn't with MultiSelect=true. Also, setting MultiSelect to false first, selecting the item and setting it true again doesn't work. This is very odd.

    ReplyDelete
  28. OK, I still don't know why it works in the simple case but not this particular more complex dialog, but the solution seems to be to do the selection in FormShow rather than in FormCreate. Unfortunately this means some ugly code.

    ReplyDelete
  29. Why ugly code? What about this:

    Idx := SomeListBox.ItemIndex;
    if Idx <> -1 then
    SomeListBox.Selected[Idx] := Idx;

    (in FormShow)

    ReplyDelete
  30. Daniela Osterhagen Not too bad. Thanks, that will work.

    ReplyDelete
  31. Daniela Osterhagen No, didn't work. For whatever reason setting ItemIndex to -1 doesn't work either. ItemIndex always ends up to be 0. I give up and use a field for this. It works now, even though it's not as neat as I'd like.
    New functionality of GExperts:
    To move the unit currently under the cursor from e.g. Interface to Implementation, press Shift+Alt+U to open the uses manager form, then press Alt+I to move the unit. Or Shift+Alt+U followed by Alt+D to delete it.
    Time to quit.

    ReplyDelete
  32. Hmmm ... this rings a bell from a loooooonnnnngggggg time back. Take a look at the code for TListBox and how it handles things when MultiSelect is True. It does not behave as expected.

    If you have MultiSelect enabled and select some cells, then unselect one, it remains with a border around it to show it's the ItemIndex, but it's not Selected. However, you can't set ItemIndex to -1 as it can't not refer to a cell. It's just damned goofy. (This is from memory, which is getting flaky these days. Read the source code for a better idea of what's going on.)

    ReplyDelete

Post a Comment