CComboBox* CSHListCtrl::ShowInPlaceComboBox(int nItem, int nSubitem,DWORD dwStyle) { // The returned pointer should not be saved // Make sure that the item is visible // My code start here if (!EnsureVisible(nItem, TRUE) ) return NULL; // Make sure that nCol is valid CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); int nColumnCount = pHeader->GetItemCount(); if( nSubitem >= nColumnCount || GetColumnWidth(nSubitem) < 10 ) return NULL; // Get the column offset int offset = 0; for(int i = 0; i < nSubitem; i++) offset += GetColumnWidth(i); CRect rect; GetItemRect(nItem, &rect, LVIR_BOUNDS); // Now scroll if we need to expose the column CRect rcClient; GetClientRect(&rcClient); if(offset + rect.left < 0 || offset + rect.left > rcClient.right) { CSize size; size.cx = offset + rect.left; size.cy = 0; Scroll(size); rect.left -= size.cx; } rect.left += offset; rect.right = rect.left + GetColumnWidth( nSubitem ) ; int height = rect.bottom - rect.top; rect.bottom += 22 * height; if (rect.right > rcClient.right) rect.right = rcClient.right; dwStyle |= WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DISABLENOSCROLL; CComboBox* pList = new CSHInPlaceComboBox(nItem, nSubitem); pList->Create(dwStyle, rect, this, IDC_INPLACE_COMBOBOX); pList->SetItemHeight(-1, height); pList->SetHorizontalExtent(GetColumnWidth(nSubitem)); CString strWindowText = GetItemText(nItem, nSubitem); if(dwStyle & CBS_DROPDOWN && !(dwStyle & CBS_DROPDOWNLIST)) { CEdit* m_pEdit = new CEdit(); m_pEdit->SubclassWindow(pList->GetDlgItem(1001)->GetSafeHwnd()); m_pEdit->SetWindowText(strWindowText); m_pEdit->SetSel(0,-1); } return pList; // My code end here }