Put ComboBox on the top of CListView

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.
hi123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vinayak KumbarSr Program ManagerCommented:
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
hi123Author Commented:
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
Vinayak KumbarSr Program ManagerCommented:
HI,

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

VinExpert
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

hi123Author Commented:
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
Vinayak KumbarSr Program ManagerCommented:
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
hi123Author Commented:
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
Vinayak KumbarSr Program ManagerCommented:
Hi,

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

VinExpert
0
hi123Author Commented:
my e-mail id is hdo@porsche.inabbdb.co.in
0
V_BapatCommented:
Look in codeguru.developer.com/listview      
0
Vinayak KumbarSr Program ManagerCommented:
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
Vinayak KumbarSr Program ManagerCommented:
Hi,

Have U got the answer from that?

VinExpert
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.