error in displaying in listbox
-
I am trying to display the records in the listbox. When I try to Initialize the listbox with the value in *View.cpp, I am getting an 'Access violation'. Can someone help fixing it. here is the code: void CListdatabaseView::OnLButtonDblClk(UINT nFlags, CPoint point) { ... ... ... CListBox *plistb = (CListBox *) GetDlgItem(IDC_LIST1); CString str1; str1.Format("%s","TESTING"); plistb->AddString(str1); ddlg.DoModal(); }
-
I am trying to display the records in the listbox. When I try to Initialize the listbox with the value in *View.cpp, I am getting an 'Access violation'. Can someone help fixing it. here is the code: void CListdatabaseView::OnLButtonDblClk(UINT nFlags, CPoint point) { ... ... ... CListBox *plistb = (CListBox *) GetDlgItem(IDC_LIST1); CString str1; str1.Format("%s","TESTING"); plistb->AddString(str1); ddlg.DoModal(); }
-
without more to go on, i would say that the most likely problem is that 'plistb' is NULL and therefore plistb->AddString() is invalid. add ASSERT (plistb); after the call to GetDlgItem() to test it.
-
I am trying to display the records in the listbox. When I try to Initialize the listbox with the value in *View.cpp, I am getting an 'Access violation'. Can someone help fixing it. here is the code: void CListdatabaseView::OnLButtonDblClk(UINT nFlags, CPoint point) { ... ... ... CListBox *plistb = (CListBox *) GetDlgItem(IDC_LIST1); CString str1; str1.Format("%s","TESTING"); plistb->AddString(str1); ddlg.DoModal(); }
I'm having the same problem. Please let me know if you have found a solution. It's mostly related to trying to add data to a listbox which is not visible to current class. Try adding the data from the CListBox's owner class and it should work. Try it from an outside class it throws an ASSERT. Let me know please.