Solved

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

Posted on 2000-03-02
6
753 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 8

Accepted Solution

by:
VinExpert earned 95 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
Independent Software Vendors: 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:VinExpert
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:VinExpert
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

687 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