?
Solved

Put ComboBox on the top of CListView

Posted on 2000-01-08
11
Medium Priority
?
374 Views
Last Modified: 2013-11-20
Sir, i have created a one Dialog, within that there is one CListView of Report-List type, & taken it's one member variable, called m_ListView. Now I have to put ComboBox on the top of the only one of the column of the CListView & when i traverse through the list with mouse click &/| with arrow up or down,   the focus should not dispose the combobox, i.e. the combobox should remain there for lifetime of the Dialog & focus should not destroy the combobox.
Please sir provide answer, I have tried in the following manner;
first i take the rectangle of the particular column & at that place i create the new combobox, but what happen with me is that the combo box disposed automatically when i traver the rows in the list, with the ExtendedRowSelection FOCUS & it is required.

in abstract way i want to put combobox on the top of the CListView such that any effect of CListView doesn't come on the ComboBox.
 
Hope for +ve response.
waiting for reply.
Thanks.
0
Comment
Question by:hi123
  • 6
  • 4
11 Comments
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2334488
Hi,

Follow the steps.

1. Add a new class sat CMyListCtrl derived from CListCtrl. replace ur definition of variable m_ListView from
CListCtrl m_ListView to
CMyListCtrl m_ListView;
U have include MyListCtrl.h for that dialog.h file.

2. In the dialog's OnInitDialog() do
CStringArray l_saTitle;
      l_saTitle.Add("Column1");
      l_saTitle.Add("Column2");
      
      for(int l_iIndex = 0;l_iIndex <l_saTitle.GetSize();l_iIndex ++)
            m_ctrlList.InsertColumn(l_iIndex+1,l_saTitle[l_iIndex],LVCFMT_LEFT,(l_saTitle[l_iIndex].GetLength()* 7) ,-1);
      
      ListView_SetExtendedListViewStyle(m_ctrlList, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_ONECLICKACTIVATE);      
      
      m_ctrlList.InsertItem(0,"");

3. Map the WM_CREATE message to CMyListCtrl class and it will look like
int CMyListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      if (CListCtrl::OnCreate(lpCreateStruct) == -1)
            return -1;
      this->SetTimer(1, 5, NULL);      
      return 0;
}

4. Map WM_TIMER message to that class and add
void CMyListCtrl::OnTimer(UINT nIDEvent)
{
      KillTimer(1);
      CRect rect;
      ListView_GetSubItemRect(this->GetSafeHwnd(), 0, 0, LVIR_BOUNDS, &rect);
      rect.right = rect.left + GetColumnWidth(0);

      m_Combo = new CComboBox;
      rect.bottom += 100;
      DWORD dwStyle = WS_BORDER|WS_CHILD|WS_VISIBLE
                              |CBS_DROPDOWNLIST|WS_VSCROLL;;
      m_Combo->Create(dwStyle, rect, this, 4545);
      CFont* font = this->GetFont();
      m_Combo->SetFont(font);
      m_Combo->AddString("1");
      m_Combo->AddString("2");
      m_Combo->AddString("3");
      m_Combo->ShowWindow(SW_SHOW);
      m_Combo->SetHorizontalExtent( GetColumnWidth(0));      
      m_Combo->SetCurSel(0);
      CListCtrl::OnTimer(nIDEvent);
}

5. Open MyListCtrl.h and add the following as public
CComboBox *m_Combo; and initialise it to NULL in the constructor.

6. Map OnNotify() to the CMyListCtrl class and place the code as
BOOL CMyListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
      HD_NOTIFY *pHDN = (HD_NOTIFY*)lParam;
      if(pHDN->hdr.code == HDN_BEGINTRACKW || pHDN->hdr.code == HDN_ENDTRACKA)
      {
            CRect rect;
            ListView_GetSubItemRect(this->GetSafeHwnd(), 0, 0, LVIR_BOUNDS, &rect);
            int Width = GetColumnWidth(0);

            //rect.left -= Width;
            rect.right = rect.left + Width;
            if(m_Combo)
            {
                  
                  m_Combo->MoveWindow(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE);
                  
            }
      }
      return CListCtrl::OnNotify(wParam, lParam, pResult);
}

7. Now compile and run the app. It will give u the combo box at first column first row, through out the life of the app. Take care of memory leaks.

If U have any prob, ask me. I have sample workspace for the same. Give me ur mail ID I will sen dit to U.
Hope this helps.

VinExpert
0
 

Author Comment

by:hi123
ID: 2337293
Sir, i want comboBox on 1St column for all no. of rows, & when i scroll trho i.e. traverse thro' arrow it should not be disposed. the combo remain there. for the same size of the bounded area of the subitem.
0
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2337350
HI,

Apply the same logic to create combo's for all rows.

VinExpert
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:hi123
ID: 2340966
sir, i have tried above but what happens to it, when i select one of the item from comboBox then it always shows the initial position of the item, Instead what i want is the current selected item should remain there.
0
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2355119
Hi,

If I have understood correctly, When U click on say column 1 of any inserted row, then a combo box should come up with some choices. Then user selects one of them, that should remain there. And when combo box looses focus, the combo should be disappeared. Is that right?

I have sample workspace to do that. If u give me Ur emailId, I will send it to u.

Cheers,

VinExpert
0
 

Author Comment

by:hi123
ID: 2361483
No, combobox should remain at corresponding possitions, but when i choose some item from combo then that item should remian selected in the combobox & also combo should remain there. And this is only for 1st Column not all columns, OK.
0
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2361733
Hi,

No Prob, I will see. Give me Ur mailID, so that I can send the sample to U.

VinExpert
0
 

Author Comment

by:hi123
ID: 2362373
my e-mail id is hdo@porsche.inabbdb.co.in
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2373394
Look in codeguru.developer.com/listview      
0
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2376879
Hi,

I have sent u the sample code. Pls go through it. I think thats what U needed.

Hope that helps u in giving ideas.

VinExpert
0
 
LVL 8

Accepted Solution

by:
Vinayak Kumbar earned 100 total points
ID: 2500294
Hi,

Have U got the answer from that?

VinExpert
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Suggested Courses

607 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