[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2000-03-02
6
Medium Priority
?
809 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 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

649 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