I have a dialog with a CListCtrl on it. The list control is setup in Report mode so I can display a table of information. I want the user to be able to click on a "cell" and edit it. To do that, I've created a CEdit object that I move and resize over the cell the user clicks on. When I do that, I put the text from the selected item in the CEdit field and select all the text. This sort of works. When I click on the CListCtrl, the CEdit object moves correctly, has the text and the cursor is there. I can edit the text. However, the text isn't selected and the border for the CEdit field isn't correctly drawn. If I move the mouse out of the CEdit field, the text is then highlighted and the border is drawn correctly. This problem does not occur if I do not move the CEdit field over the cell to be edited (of course, the field is then in the wrong place). Below is the code that runs when the user clicks on the list control:
void Edit_Constraints_Page::OnNMClickList1(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE) pNMHDR;
//
// The operator clicked on the list ctrl, presumably because he wants to
// edit something. First, get the row number that he clicked in.
//
m_current_parameter_index = temp->iItem;
//
// Now get the column number
//
nSubItem = temp->iSubItem;
if(nSubItem == 0 || nSubItem == -1 || m_current_parameter_index == -1)
{
return ;
}
//
// Retrieve the text of the selected subItem from the list
//
CString str = m_list_ctrl.GetItemText(m_current_parameter_index, nSubItem);
RECT rect1,rect2;
CRect rect3;
m_list_ctrl.GetSubItemRect(temp->iItem, temp->iSubItem,LVIR_BOUNDS,rect3);
//Get the Rectange of the listControl
::GetWindowRect(temp->hdr.hwndFrom,&rect1);
//Get the Rectange of the Dialog
::GetWindowRect(m_hWnd,&rect2);
int x = rect1.left - rect2.left;
int y = rect1.top - rect2.top;
int width = rect3.Width();
int height = rect3.Height();
if (m_current_parameter_index != -1)
{
//
// Move the edit box used for editing things in the list control over the
// "cell" that was clicked on...
//
m_list_edit_box.SetWindowPos(&wndTop, rect3.left + x + 1,
rect3.top + y,
rect3.Width(), rect3.Height(),
NULL);
//
// Show the text box (when not editing, we hide it) and give it the focus.
//
m_list_edit_box.Invalidate();
m_list_edit_box.ShowWindow(SW_SHOW);
m_list_edit_box.SetFocus();
//
// Put the list item text in the text box and highlight the text.
//
m_list_edit_box.SetWindowText(str);
m_list_edit_box.SetSel(0, -1);
m_list_edit_box.SetWindowPos(&wndTop, rect3.left + x + 1,
rect3.top + y,
rect3.Width(), rect3.Height(),
NULL);
m_list_edit_box.Invalidate();
*pResult = 0;
}
}
Does any one have an idea what I'm doing wrong?
Thanks,
Jim