Access Violation During adding items in List Control ( CXListCtrl )....
-
Hello All, I am developing a sample SDI application in VC++ 6.0 on Windows 2000 Professional. My view class is derived from "CFormView". I am using this List control taken from http://www.codeproject.com/listctrl/xlistctrl.asp on my Form. Creation and initial display are proper and when i try to add an Item it gives access violation. Here is the code used to update the List control.
BOOL CMyView::UpdateList (int l_iRow, CInfo *l_oInfo) { CString l_strTemp; int l_iRowCount = 0; // ID l_strTemp.Format ("%d", l_oInfo->m_lID); if (l_iRow == -1) { // add at the end of the list l_iRow = m_oTabList.GetItemCount (); m_oTabList.InsertItem(l_iRow, l_strTemp, RGB(255, 0, 0), RGB(255, 255, 255)); } else { l_iRow--; m_oTabList.SetItemText (l_iRow, l_iRowCount, l_strTemp); } l_iRowCount++; ....
If I debug and see the above function is executing fine. but it fails while drawing the items in Line Number 842 of XListCtrl.cpp in Function "DrawTextm_HeaderCtrl.GetItem(nSubItem, &hditem);
In the GetItem the m_hWnd is NULL so code in AFXCMN.INL gives Access Violation_AFXCMN_INLINE BOOL CHeaderCtrl::GetItem(int nPos, HDITEM* pHeaderItem) const { ASSERT(::IsWindow(m_hWnd)); return (BOOL)::SendMessage(m_hWnd, HDM_GETITEM, nPos, (LPARAM)pHeaderItem); }
Since ASSERT won't execute in Release mode it is working fine in Release mode. The code used to insert column is belowm_oList.SetExtendedStyle(m_oList.GetStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); // Insert the columns for the list control m_oList.InsertColumn (0, _T("ID"), LVCFMT_CENTER, 40); m_oList.InsertColumn (1, _T("No"), LVCFMT_CENTER, 80); m_oList.InsertColumn (2, _T("Time"), LVCFMT_CENTER, 120);
After this code I am inserting new items. Can any one suggest what may be the problem. Thanks in Advance Ravi -
Hello All, I am developing a sample SDI application in VC++ 6.0 on Windows 2000 Professional. My view class is derived from "CFormView". I am using this List control taken from http://www.codeproject.com/listctrl/xlistctrl.asp on my Form. Creation and initial display are proper and when i try to add an Item it gives access violation. Here is the code used to update the List control.
BOOL CMyView::UpdateList (int l_iRow, CInfo *l_oInfo) { CString l_strTemp; int l_iRowCount = 0; // ID l_strTemp.Format ("%d", l_oInfo->m_lID); if (l_iRow == -1) { // add at the end of the list l_iRow = m_oTabList.GetItemCount (); m_oTabList.InsertItem(l_iRow, l_strTemp, RGB(255, 0, 0), RGB(255, 255, 255)); } else { l_iRow--; m_oTabList.SetItemText (l_iRow, l_iRowCount, l_strTemp); } l_iRowCount++; ....
If I debug and see the above function is executing fine. but it fails while drawing the items in Line Number 842 of XListCtrl.cpp in Function "DrawTextm_HeaderCtrl.GetItem(nSubItem, &hditem);
In the GetItem the m_hWnd is NULL so code in AFXCMN.INL gives Access Violation_AFXCMN_INLINE BOOL CHeaderCtrl::GetItem(int nPos, HDITEM* pHeaderItem) const { ASSERT(::IsWindow(m_hWnd)); return (BOOL)::SendMessage(m_hWnd, HDM_GETITEM, nPos, (LPARAM)pHeaderItem); }
Since ASSERT won't execute in Release mode it is working fine in Release mode. The code used to insert column is belowm_oList.SetExtendedStyle(m_oList.GetStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); // Insert the columns for the list control m_oList.InsertColumn (0, _T("ID"), LVCFMT_CENTER, 40); m_oList.InsertColumn (1, _T("No"), LVCFMT_CENTER, 80); m_oList.InsertColumn (2, _T("Time"), LVCFMT_CENTER, 120);
After this code I am inserting new items. Can any one suggest what may be the problem. Thanks in Advance RaviRavi Sankar S wrote: m_HeaderCtrl.GetItem(nSubItem, &hditem); In the GetItem the m_hWnd is NULL so code in AFXCMN.INL gives Access Violation Check how m_HeaderCtrl is initialized. The m_hWnd in GetItem is the one from m_HeaderCtrl, which does seem to be an initialized object in your case. Ravi Sankar S wrote: Since ASSERT won't execute in Release mode it is working fine in Release mode. I would not rely on such a statement. If it fails in Debug, it does not work either in Release, it is only that the problem does not assert immediately (the effects of what goes wrong does not show immediately). But it can bring unexpected (and sometimes unrelated) errors later for the program user :~ ... So better be sure to find what goes wrong. ~RaGE();