?
Solved

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

Posted on 2000-03-02
6
Medium Priority
?
840 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:balugaa
  • 3
  • 2
6 Comments
 
LVL 8

Accepted Solution

by:
Vinayak Kumbar earned 380 total points
ID: 2576086
Hi,

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

VinExpert
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2576102
Hi VinExpert, couldn't you post the important code or at least an URL where it could be found?
0
 

Author Comment

by:balugaa
ID: 2576134
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.

thanx
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2576330
Hi,

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
      LVHITTESTINFO SubHitTest;
      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;
            DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_TABSTOP;
            ListView_GetSubItemRect(this->GetSafeHwnd(), SubHitTest.iItem, SubHitTest.iSubItem, LVIR_LABEL, &rect);
            
            //delete prev combo if exists
            if(m_MyCombo)
            {
                  if(m_bLongLiveCombo)
                  {
                        m_MyCombo->OnKillFocus(this);
                  }
                  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
            m_MyCombo->AddString("String1");
            m_MyCombo->AddString("String2");
            m_MyCombo->AddString("String3");
            
            // Set the proper font
            CFont* font = this->GetFont();
            m_MyCombo->SetFont(font);

            //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)
            {
                  m_MyCombo->SetCurSel(l_iToBeSelected);
            }
            else
                  m_MyCombo->SetCurSel(0);

            //Show It
            m_MyCombo->ShowWindow(SW_SHOW);      
            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)
{
      CComboBox::OnKillFocus(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;
      this->DestroyWindow();
}

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.
 
VinExpert
0
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2576393
Hi,

Here is the sample which can be looked at.

http://codeguru.developer.com/listview/drop_down_list.shtml

VinExpert
0
 

Author Comment

by:balugaa
ID: 2579359
Thanx VinExpert,
It worked Fine.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
In this post we will learn different types of Android Layout and some basics of an Android App.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
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.

840 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