Solved

How to disable ComboBox automatic scrolling?

Posted on 2000-03-26
9
484 Views
Last Modified: 2013-11-20
I have class MyComboBox. When I select an item from a ListBox, ComboBox is scrolled automatically that selected item is the first on ListBox. How could I disable it?
I tried to do it in OnDropDown, OnLButtonDown in OnClouseUp. Always without success!
I would like to control scrolling by my code!

Thanks all!
0
Comment
Question by:si124
  • 5
  • 4
9 Comments
 
LVL 1

Accepted Solution

by:
yarond earned 100 total points
ID: 2660165
Well, it's not very elegant, but it will work.
The combobox scrolls the drop-down listbox to the selected item. So what you can do is on the OnDropDown use SetCurSel(-1) which will clear the selection.
However, if you want the selected item to remain selected when you close the drop-down without selecting a different one, before using SetCurSel(-1) use GetCurSel() and keep the return value, and then on OnCloseUp check if GetCurSel()==CB_ERR, and if so (no new item was selected) use SetCurSel(m_PrevSelection).
It will also work properly on the first run because CB_ERR==-1 so if nothing was selected no harm is done. Although it would be much nice to search for this condition on the OnDropDown and not count on it...
0
 

Author Comment

by:si124
ID: 2661688
Thank you very much for your help.
I managed to control scrolling by myself.

I would like to leave selected text in EditBox on DropDown. In this case EditBox is empty (unusal).
Is it possible to fix it?

Thanks!
0
 
LVL 1

Expert Comment

by:yarond
ID: 2663534
I found a totally different solution, which is IMHO much better, and answers all your requirements (that I know of).
In the OnDropDown, assuming you have a CComboBox control named m_Combo, use either:
::PostMessage(m_Combo.m_hWnd,CB_SETTOPINDEX,0,0);
or:
m_Combo.PostMessage(CB_SETTOPINDEX,0,0);
If you use PostMessage and not SendMessage it gets processed only after the dropdown operation is finished, and so it scrolls to the top position.
0
 

Author Comment

by:si124
ID: 2663810
I used this option before!!!
I send my own WM_USER+1 message and in it I scroll down ListBox to right position.
I can't use SetTopIndex because I have header control on the top of ListBox, so I have to leave it on the top!
Your last solution was OK, except the problem of empty EditBox!
Is there any other possibility to solve my problem!

Thanks!



0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:si124
ID: 2663812
I have to repair myself. I meant Post WM_USER+1 message!
0
 
LVL 1

Expert Comment

by:yarond
ID: 2663881
One rather ugly option would be to put a different editbox on top of the combobox's editbox, and in OnDropDown, copying the selected item to it, making it visible, and only then clearing the selection.
But I don't exactly understand how does the header control prevent you from using SetTopIndex. Where exactly is the header control placed, and what happens to it when you use SetTopIndex?
0
 

Author Comment

by:si124
ID: 2663990
My header control is child window of ListBox. When I use SetTopIndex, windows is scrolled so header control disappears from the view.
0
 
LVL 1

Expert Comment

by:yarond
ID: 2664683
I can't think of a better solution for you right now. I'll withdraw my answer so someone else might be able to help you.
0
 

Author Comment

by:si124
ID: 2665147
In any case thank you very very much for your help!!!!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need to retreive data from .TFS file exported by DVR 8 177
Expand macro to ask for filename column 8 37
List out all word 7 257
How to convert MFC::CString to UTF8 wchar_t* 10 141
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now