Solved

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

Posted on 2000-03-02
6
715 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:
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adapt this command to show who installed 29 108
iSeries DB2 Query 2 95
ShiftLeft challenge 21 81
Updating statistics with error notification email in SQL server 4 95
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

773 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