CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Sep 1999
    Location
    malaysia
    Posts
    191

    [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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured