All the issues mentioned in above comments, as well as one or two others have now been fixed. These issues are: - GetItemText should now work correctly for all inserted cell types. - DeleteAllItems should also work correctly. The fixes are in both zipped files: VS6.0 and VS2010. VS2010 has a colour picker not in the VS6.0 version.Reply
Sorry last message was unreadable.
This is a bug. Thank you for pointing this out again.
To correct: Make following changes in file ConfigListCtrl.inl:
BOOL CConfigListCtrl::DeleteItem(int nItem)
{
RemoveCtrlRow(nItem);
m_Bookmarks.RemoveAt(nItem);
return CListCtrl::DeleteItem(nItem);
}
BOOL CConfigListCtrl::DeleteAllItems()
{
RemoveAllCtrls();
m_Bookmarks.RemoveAll();
return CListCtrl::DeleteAllItems();
}
The first function is not used by DeleteAllItems, but fixes an issue when want to delete a single row. I have not tested deletion of columns yet.
Reply
This is a bug. Thank you for pointing this out again. To correct: Make following changes in file ConfigListCtrl.inl: BOOL CConfigListCtrl::DeleteItem(int nItem) { RemoveCtrlRow(nItem); m_Bookmarks.RemoveAt(nItem); return CListCtrl::DeleteItem(nItem); } BOOL CConfigListCtrl::DeleteAllItems() { RemoveAllCtrls(); m_Bookmarks.RemoveAll(); return CListCtrl::DeleteAllItems(); } The first function is not used by DeleteAllItems, but fixes an issue when want to delete a single row. I have not tested deletion of columns yet.
Replyuse second DeleteAllItems,crash!
Replythank you answer! In my project ,i Use MFC in a Static Library,i build CellCtrls into a dll/lib(dynamic/static),the project crash. //#pragma comment(lib,"CellCtrls60S.lib") static //#pragma comment(lib,"CellCtrls60.lib") dynamic how to do? thanks!
ReplyI have posted a new version of source, both for Visual Studio 6.0 and 2010 compilers. This has fixes for the bug mentioned above, as well as other corrections. Hopefully, this will not take too long to be reviewed and published.
ReplyOoops! In focusing on details, I overlooked the obvious! Thank you for pointing this out to me.
This is a bug and correction requires not many changes. The same fault occurs for all the controls. I shall publish an updated version of my source code.
In the meanwhile, here are the required fixes:
In CCellCtrl, add function in CellCtrl.h file:
virtual CString GetSelectedTextValue()
{
return m_strText;
}
In CCellCheckBox, add function in CellCheckBox.h file:
virtual CString GetSelectedTextValue()
{
return (m_bSelected? _T("1") : _T("0")) + m_strText;
}
(I personally donbt like having a function as virtual when it should be inlined, but this will do for now b I need to make other changes in CCellCheckBox, to make it consistent with the other controls).
Change make changes in following CconfigListCtrl.cpp file functions as follows:
BOOL CConfigListCtrl::SetItem(int nItem, int nSubItem, CCellCtrl *pCellCtrl, LPCTSTR lpszDefaultTextValue /* = "\0"*/)
{
ASSERT(pCellCtrl);
InsertCtrl(nItem, nSubItem, pCellCtrl);
pCellCtrl->Initialize(m_hWnd, lpszDefaultTextValue);
return SetItem(nItem, nSubItem, pCellCtrl->GetSelectedTextValue()); // This line modified
}
void CConfigListCtrl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
BOOL bCall = TRUE;
if (m_ActiveCell.m_lItem != -1 && m_ActiveCell.m_lSubItem != -1)
{
bCall = m_ActiveCell.m_pActiveCtrl->OnChar(nChar, nRepCnt, nFlags);
InvalidateActiveCellRect();
SetItem(m_ActiveCell.m_lItem, m_ActiveCell.m_lSubItem, m_ActiveCell.m_pActiveCtrl->GetSelectedTextValue()); // This line added
}
if (bCall)
CListCtrl::OnChar(nChar, nRepCnt, nFlags);
}
void CConfigListCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
BOOL bCall = TRUE;
LVHITTESTINFO Info;
CCellCtrl *pCellCtrl = NULL;
BOOL bCaretExisted = m_bCaretExists;
RECT rcSubItem;
Info.flags = 0;
Info.pt = point;
int iItem = SubItemHitTest(&Info);
if (IsOnCellCtrl(Info.iItem, Info.iSubItem, &pCellCtrl))
{
m_ActiveCell.m_lItem = Info.iItem;
m_ActiveCell.m_lSubItem = Info.iSubItem;
if (m_ActiveCell.m_pActiveCtrl && m_ActiveCell.m_pActiveCtrl != pCellCtrl)
m_ActiveCell.m_pActiveCtrl->OnKillActive();
m_ActiveCell.m_pActiveCtrl = pCellCtrl;
// The bounding rect for a combobox can be inaccurate without couple of lines below.
// Try commenting these and: use mousewheel up and down several time, then click
// on combo to see.
GetSubItemRect(Info.iItem, Info.iSubItem, LVIR_LABEL, (CRect &)rcSubItem);
pCellCtrl->SetWindowRect(&rcSubItem);
pCellCtrl->OnLButtonDown(nFlags, point);
SetItem(m_ActiveCell.m_lItem, m_ActiveCell.m_lSubItem, m_ActiveCell.m_pActiveCtrl->GetSelectedTextValue()); // This line added
if (m_bCaretExists)
pCellCtrl->OnCaretHandlingLButtonDown(nFlags, point);
SetFocus(); // only get focus when left mouse button is up otherwise
}
else
DeActivateCell();
this->Invalidate(FALSE); // Have to put this line, otherwise change of state of a cell is slow to show up.
if (bCall)
CListCtrl::OnLButtonDown(nFlags, point); // setfocus is called in here: m_bCaretExists is always true after this line
if (pCellCtrl && !bCaretExisted)
pCellCtrl->OnCaretHandlingLButtonDown(nFlags, point);
}
LRESULT CConfigListCtrl::OnCellCtrlMsg(WPARAM wParam, LPARAM lParam)
{
if (m_ActiveCell.m_lItem != -1 && m_ActiveCell.m_lSubItem != -1)
{
m_ActiveCell.m_pActiveCtrl->OnCellCtrlMsg(wParam, lParam);
SetItem(m_ActiveCell.m_lItem, m_ActiveCell.m_lSubItem, m_ActiveCell.m_pActiveCtrl->GetSelectedTextValue()); // This line added
}
return TRUE;
}
Reply
in CCellComboBox . i GetItemText(nItem,1) ,but is NULL; how?? thanks!
Reply