 |
|
 |
Hi all,
I work in an MFC project. How can i remove a combo box item during runtime so that it will not appear from the next time onwards?
Thanks in advance
|
|
|
|
 |
|
 |
How does one actually go about setting which items must be enabled and which disabled, because right now, its just randomly setting some as enabled and some as disabled. So i'm not really sure how to go about this. Can anybody help?
Thanks
sc
|
|
|
|
 |
|
 |
Add this into the code
void EnableItem(int nIndex, bool bEnable);
void CExtendedComboBox::EnableItem(int nIndex, bool bEnable)
{
if (nIndex < GetCount())
{
if (bEnable)
SetItemData(nIndex, 1);
else
SetItemData(nIndex, 0);
}
}
Ask if you need more help
HY
|
|
|
|
 |
|
 |
I tried this code but error in GetCount() and SetItemData() function ,so pls reply what can i do and send the full related code for this function..
With regards,
P.Uthaman
|
|
|
|
 |
|
 |
canst you send my a Project(V++ 6.0 or later) with the Class "ExtendedComboBox".
thank
Karli
|
|
|
|
 |
|
 |
http://www.codeproject.com/combobox/disableditemscombobox.asp?select=5310&df=100&forumid=538#xx5310xx
Junior Programmer (Newbie)
From Scotland
|
|
|
|
 |
|
 |
Hi,
my need is quit diferent,
When populating the list, i can't know if the items are enable or not (for performance).
I just want to forbid selection when the user try to do so.
Who can I do ?
|
|
|
|
 |
|
 |
Hi,
i am also in the same problem.Can u help me out, how to disable the combobox depending on text selected from another combo box
Laxman
|
|
|
|
 |
|
 |
Sorry, but I did'nt find solution.
|
|
|
|
 |
|
 |
If you mean enable/disable items when dropping down the display list, you can use:
ON_CBN_DROPDOWN(IDC_COMBO, &CComboDlg::OnCbnDropdownCombo)
|
|
|
|
 |
|
 |
i like the combobox and seems very good for VC++ but i have an application in VB and i'm looking for a similar functionality therein. ne inouts wud b appreciated.
thnx,
Manisha
|
|
|
|
 |
|
 |
Very useful, but it keeps defaulting to 16 pixels high for me, which is out of sync with all my other combo boxes which are 13 pixels high. I can't figure out how to override this default.
Anyone know the answer to this one?
|
|
|
|
 |
|
 |
Îs there any way to prevent some items to be listed in the listbox of the comboBox. But the program should be able to select that item using SetCurSel()
|
|
|
|
 |
|
|
 |
|
 |
These types of commercial ads in the comments should be removed.
I do not think I would ever deal with a company that tries to market
their products in this manner. Unscrupulous... if they advertise this
way, they would probably sell you garbage code and laugh all the way
to the bank.
|
|
|
|
 |
|
 |
Hi!
I need to know, with the use of your CExtendedComboBox class, how to disable/enable items depending
on the actions that the user takes.
All I was able to do, up to now, is to disable the items that I wish at creation. But I want to be able
to enable them back again depending on what actions the user takes.
My guess is to provoke the call of DrawItem but what message do I need to sent so the function will be
executed again? Tried sending WM_PAINT or WM_DRAWITEM without any success...
Do I have to explicitly call DrawItem and provide my own LPDRAWITEMSTRUCT?
Any help would be appreciate
|
|
|
|
 |
|
 |
The best way is to InvalidateWindow() or InvalidateRect() (or MFC Invalidate())
|
|
|
|
 |
|
 |
Hi,
good class!!!!
But, ... all boxes I create are higher compared the
CComboBox. I looked into the code and it seams that
MeasureItem is not called at all (it's a noop anyway).
My guess is that the height of the characters is not
handled correctly. Any idea?
|
|
|
|
 |
|
 |
Hi,
my first guess was "MeasureItem". But according the MSDN it is not called for resource based controls.
Finally I gave up finding a clean solution and use that work around:
Add something similar to the OnInitDialog()
// workaround for CExtendedComboBox being to high
UINT nBoxHeight = m_box_baud.GetItemHeight( -1 ); // read from a regular combo box
m_box_port.SetItemHeight( -1, nBoxHeight ); // and fix the wrong size
How it works:
I have two combo boxes:
- m_box_baud is a regular CComboBox
- m_box_port is a CExtendedComboBox
The height of the CComboBox is used to fix the wrong height of CExtendedComboBox .
Both boxes are subclassed with DDX_Control in:
void CMyDialog::DoDataExchange(CDataExchange* pDX)
{
.......
//{{AFX_DATA_MAP(CMyDialog)
DDX_Control(pDX, IDC_PORT, m_box_port);
DDX_Control(pDX, IDC_BAUD, m_box_baud);
//}}AFX_DATA_MAP
}
Not the best and clean solution, but it helps for now.
Any better idea??
Dieter Fauth, Hand Held Products a Welch Allyn affilate
|
|
|
|
 |
|
 |
Try doing this. It is not too elegant, but it is better than having two Combo Boxes, as some one else did to solve this problem.
LRESULT CExtendedComboBox::OnCtlColor(WPARAM,LPARAM lParam)
{
if (m_ListBox.m_hWnd==NULL && lParam!=0 && lParam!=(LPARAM)m_hWnd)
{
m_ListBox.SubclassWindow((HWND)lParam);
if (GetCount())
{
CRect rect;
GetClientRect(&rect);
m_ListBox.SetWindowPos(&wndTop,
0,0, rect.Width(),(min(15,GetCount()+1))*GetItemHeight(0),
SWP_NOMOVE);
}
}
return Default();
}
|
|
|
|
 |
|
 |
When combo box is selected but not dropped,
a few keyboard keys must be handled
during key down event:
VK_UP, VK_DOWN, VK_PRIOR, VK_NEXT,
and for CBS_DROPDOWNLIST style still VK_HOME, VK_END.
e.g.
void CExtendedComboBox::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
int nIndex = GetCurSel();
if (nChar == VK_DOWN) {
if (nIndex+1 < GetCount() {
if (!IsItemEnabled(nIndex+1)) {
for (int i = nIndex+2; i < GetCount(); i++) {
if (IsItemEnabled(i)) {
SetCurSel(i);
break;
}
}
return;
}
}
}
// ... similar for
// VK_UP, VK_HOME, VK_END, VK_PRIOR, VK_NEXT
CComboBox::OnKeyDown(nChar, nRepCnt, nFlags);
}
|
|
|
|
 |
|
 |
Hi,
I tested the code with my CBS_DROPDOWNLIST combo and the code does not work.
Andreas
|
|
|
|
 |
|
 |
Haven't you forgotten to use CBS_OWNERDRAWFIXED and CBS_HASSTRINGS? (Bottom line: The code works for me. If it doesn't work for you, we need to find where's the difference.
|
|
|
|
 |
|
 |
Hi,
works fine for me too.
|
|
|
|
 |
|
 |
Yup, I saw the same thing. It is possible to select a disabled item in a drop list using accelerator keys (I can't remember exactly which ones off the top of my head, but HOME and END were certainly among them).
In addition it was possible to select a disabled item by (if I remember rightly) tabbing to another control whilst the list was dropped.
When I used this control a little while back I prepared a patched version (renamed as CDisabledItemsComboBox to integrate into our project) which addressed these issues, along with a demo project which exercised both types of control.
If you need it you can download a copy from http://website.lineone.net/~andy.metcalfe/code_archive/downloads/ http://www.riverblade.co.uk/downloads/archive/DisabledComboBoxTest.zip[^].
modified on Tuesday, April 27, 2010 12:23 PM
|
|
|
|
 |