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
https://stackoverflow.com/questions/39213803/what-can-prevent-a-listbox-item-to-be-selected
If you disable MultiSelect, does it work as expected in the large app?
ReplyDeleteHow about:
SomeListBox.SetFocus;
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.
ReplyDeleteOk, one cross post too far.
ReplyDeleteIf 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.
ReplyDeleteDavid Schwartz Just curious: why would that reply be flagged or deleted?
ReplyDeleteI'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.
ReplyDeleteOK, 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?
ReplyDeleteBill 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.
ReplyDeleteEspecially 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.
ReplyDeleteIt'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.
ReplyDeleteSo, 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.
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.
ReplyDeleteCome 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.
ReplyDeleteI have now deleted the question on SO. Thanks to those who tried to help me out.
ReplyDeleteBtw: 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.
Yup, that's what happens to an awful lot of otherwise perfectly legitimate questions on SO ... the authors are bullied into deleting them.
ReplyDeleteAttila Kovacs actually no, most of the lines are simple add-calls to fill the list view. I only tried to explicitly call SetFocus once.
ReplyDeleteThomas Mueller
ReplyDeleteThat was my thought, simply to get a clue what mechanisms are in play.
Problem is that SO is not forum. It is not for discussion, but for providing answers to specific questions with clear problem statement.
ReplyDeleteYour 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.
David Schwartz You would guess right. answer that does not answer the question would get deleted.
ReplyDeleteAgain, 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)
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.
ReplyDeleteAttila Kovacs Sorry! ;-) I believe you can mute this thread.
ReplyDeleteAttila Kovacs ;-) You're welcome to share your opinions, too. Ah, you did already. ;-) OK, I shut up already (regarding SO).
ReplyDeleteAttila Kovacs No i8n
ReplyDeleteFWIW, 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.
ReplyDeleteI'll have to check the code, but I think sorted is originally already set in the object editor and not changed at all.
ReplyDeleteAttila 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.
ReplyDeleteDavid 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.
ReplyDeleteBill Meyer regarding disabling Multiselect: Yes, it works as expected then. One more data point.
ReplyDeleteThomas 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....
ReplyDeleteBill 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.
ReplyDeleteI 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.
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.
ReplyDeleteWhy ugly code? What about this:
ReplyDeleteIdx := SomeListBox.ItemIndex;
if Idx <> -1 then
SomeListBox.Selected[Idx] := Idx;
(in FormShow)
Daniela Osterhagen Not too bad. Thanks, that will work.
ReplyDeleteDaniela 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.
ReplyDeleteNew 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.
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.
ReplyDeleteIf 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.)