-
May 18th, 2007, 04:02 AM
#1
[RESOLVED] Of CComboBox and CListCtrl on a CDialog
Hi all gurus,
Thought this was simple and straight forward but got stuck with the most trivial problem and in need of your help...
I have a ListCtrl on a dialog and all I am trying to do is paste a CComboBox object on the fly when user clicked on the List Control, I filled the CComboBox with values and when the user selects an item in the ComboBox it will update the column in the ListCtrl..
I inherit a new class from CComboBox and named it CComboBoxItem and overide the CComboBoxItem::OnSelchange().
On the click event of the ListCtrl, I had created the CComboBoxItem object on top of the column which the user clicked...all is fine, but when user selects an item in the CComboBoxItem, the OnSelchange was NOT triggered??..when I created it, I set the parent as the CListCtrl. But when I set the parent as the Dialog holding the CListCtrl, the OnSelchange event got triggered...
Any ideas why?? Here's a snippet of the codes
Code:
void CSettingDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
NMLISTVIEW & nm = *(NMLISTVIEW *) pNMHDR; //This converts the pNMHDR to the specific column and row
if (nm.iItem==-1||nm.iSubItem==0)
{
if(m_pCombo)
{
m_pCombo->DestroyWindow();
delete m_pCombo;
this->m_pCombo=NULL;
}
return;//No need to go on user clicked on empty area or on column 1...no editing
}
CListCtrl* pList=(CListCtrl*)this->GetDlgItem(IDC_LIST1);
CRect rect;
pList->GetSubItemRect(nm.iItem,nm.iSubItem,LVIR_LABEL,rect);
if(m_pCombo)
{
m_pCombo->DestroyWindow();
delete m_pCombo;
this->m_pCombo=NULL;
}
this->m_pCombo=new CComboBoxItem;
int nHeight=rect.Height();//Just to save the height
rect.bottom+=70;
this->m_pCombo->Create(WS_VISIBLE|WS_CHILD|CBS_DROPDOWNLIST|WS_VSCROLL,rect,pList,NULL);
//But if I did this, the CComboBoxItem::OnSelchange event got triggered??
//this->m_pCombo->Create(WS_VISIBLE|WS_CHILD|CBS_DROPDOWNLIST|WS_VSCROLL,rect,this,NULL);
this->m_pCombo->SetDroppedWidth(70);
this->m_pCombo->SetFont(pList->GetFont());
//and so forth.....
}
//Here's another snippet from CComboBoxItem
BEGIN_MESSAGE_MAP(CComboBoxItem, CComboBox)
//{{AFX_MSG_MAP(CComboBoxItem)
ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelchange)
ON_CONTROL_REFLECT(CBN_CLOSEUP, OnCloseup)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
Help...pls
Regards
Mustafa
Last edited by Mustafa; May 18th, 2007 at 04:08 AM.
______________________________
To err is human, it's the computer that causes blunders !!!
DO: Dazzle me with your intelligence
DON'T : Confuse me with your bullshit
-
May 18th, 2007, 01:56 PM
#2
Re: Of CComboBox and CListCtrl on a CDialog
Check out the LVEdit.zip source included in the post "Need help building a multicolumn list box".
The source allows the user to edit a list control item. When the user double clicks a list item, a combobox, edit control, or spin control item is presented to the user.
-
May 20th, 2007, 09:04 PM
#3
Re: Of CComboBox and CListCtrl on a CDialog
Thanks Arjay,
The solution looks great....but what I need is the clarification of why when the CComboBoxItem object when given the CListCtrl as its parent doesnt get the reflected notification of the Selchange event but if the CDialog is given as the parent instead, the Selchange event reflected notification was triggered.
I still need help here....
Thanks very much for the sample...
Regards
Mustafa
______________________________
To err is human, it's the computer that causes blunders !!!
DO: Dazzle me with your intelligence
DON'T : Confuse me with your bullshit
-
May 21st, 2007, 03:42 AM
#4
Re: Of CComboBox and CListCtrl on a CDialog
Because every mouse event in initially handled by Dialog procedure, then it is redirected to the Dialog's child control, if any...
In your case the combobox is not a child of the dialog, so the double-click is redirected only to the list control. You, however, could yourself handle mouse double-click in your CListCtrl derived class, check the message position, and if it is within the combo-box position SendMessage a user defined message to the combobox causing it to do what you want.
-
June 11th, 2007, 04:43 AM
#5
Re: Of CComboBox and CListCtrl on a CDialog
I have finally resolved this issue...what I did was to create a member variable in CDialog object of the type CListCtrl using the Classwizard and let it create the entry in the DoDataExchange function of the CDialog.
And guess what!!! My ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelchange) in the derived CComboBox class got fired......
It looked like this:
Code:
void CSettingDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSettingDlg)
DDX_Control(pDX, IDC_LIST1, m_List1);
DDX_Text(pDX, IDC_EDIT1, m_strCompanyName);
Hope it helps anyone out there...
Cheers...
______________________________
To err is human, it's the computer that causes blunders !!!
DO: Dazzle me with your intelligence
DON'T : Confuse me with your bullshit
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|