• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 868
  • Last Modified:

Adding a combobox to the first column of a list control in report mode

Can Anyone help.. I am trying to add a combobox as the first subitem for a number of rows in a list control with the Report style set.
Basically column one of the list control will be comboboxes, that the user can drop down to select appropirate values. Each row is to have a combobox, as the first subitem. hope this makes sense.
  • 3
  • 2
1 Solution
Vinayak KumbarSr Program ManagerCommented:

I have got the sample, plz give me Ur mail ID I will send it to U.

Hi VinExpert, couldn't you post the important code or at least an URL where it could be found?
balugaaAuthor Commented:
I think It would be better is you listed the URL as part of the question just incase anyone else may look at it in the future.

So please post the URL.

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Vinayak KumbarSr Program ManagerCommented:

The summary is as follows

Follow the steps.

1. Add a new class say CMyListCtrl derived from CListCtrl. replace ur definition of variable added using classwizard say m_ListView from
CListCtrl m_ListView to
CMyListCtrl m_ListView;
U have include MyListCtrl.h for that dialog.h file.

2. Add the new class usinf classwizard say CMyComboBox derived from CComboBox.

3. Insert an object of that class into the CMyListCtrl as in MyListCtrl.h
CMyComboBox *m_MyCombo;
U have to include the "MyComboBox.h" file for it.

4. In the costructor initialize it as
m_MyCombo = NULL;

5. Then map the LBUTTONDOWN handler for the CMyListCtrl and modify it something as

void CMyListCtrl::OnLButtonDown(UINT nFlags, CPoint point)
      //Get where user has clicked
      SubHitTest.pt = point;
      ListView_SubItemHitTest(this->GetSafeHwnd(), &SubHitTest);
      //Put combo box if item is correct and it is second column
      if(SubHitTest.iItem != -1 && SubHitTest.iSubItem == 0)
            CRect rect;
            ListView_GetSubItemRect(this->GetSafeHwnd(), SubHitTest.iItem, SubHitTest.iSubItem, LVIR_LABEL, &rect);
            //delete prev combo if exists
                  delete m_MyCombo;
                  m_MyCombo = NULL;
            m_MyCombo = new CMyComboBox(SubHitTest.iItem, SubHitTest.iSubItem);
            rect.top -= 3;
            rect.bottom += 100;
            m_MyCombo->Create(dwStyle, rect, this, 4545);

            //Fill the combo members
            // Set the proper font
            CFont* font = this->GetFont();

            //Get What text to display.
            CString l_StrTemp;
            l_StrTemp = GetItemText(SubHitTest.iItem, SubHitTest.iSubItem);
            int l_iToBeSelected = m_MyCombo->FindString(-1, l_StrTemp);
            if(l_iToBeSelected >= 0)

            //Show It
            m_bLongLiveCombo = TRUE;
            m_MyCombo->SetItemHeight(-1, 13);            
      CListCtrl::OnLButtonDown(nFlags, point);

6. here m_bLongLiveCombo is a boolean flag initialised to FALSE,

7. Map the OnKillFocus() to the CMyComboBox and modify it as
void CMyComboBox::OnKillFocus(CWnd* pNewWnd)
      int Selection = GetCurSel();
      CString str;

      if(Selection >= 0)
            GetLBText(Selection, str);
      ((CMyListCtrl *)GetParent())->SetItemText(m_Row, m_Col, str);
      ((CMyListCtrl *)GetParent())->m_bLongLiveCombo = FALSE;

8. Open the MyComboBox.h and add one more constructor and variables as
CMyComboBox(int Row, int Col);
int m_Row, m_Col;

9. Then in the overloaded constructor do
CMyComboBox::CMyComboBox(int Row, int Col)
      m_Row = Row;
      m_Col = Col;

That will insert U the combo box in the first column of the list control, whenever user wants to select something from the combo. Hope this u the idea for inserting the combo.
Vinayak KumbarSr Program ManagerCommented:

Here is the sample which can be looked at.


balugaaAuthor Commented:
Thanx VinExpert,
It worked Fine.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now