Solved

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

Posted on 2000-03-02
6
678 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
Comment Utility
Hi,

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

VinExpert
0
 
LVL 30

Expert Comment

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

Author Comment

by:balugaa
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 8

Expert Comment

by:VinExpert
Comment Utility
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
Comment Utility
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
Comment Utility
Thanx VinExpert,
It worked Fine.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 30
List out all word 7 220
move a line in eclipse 3 60
FizzBuzz challenge 9 71
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: 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…
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 tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now