Problem with List Control in visual c++
-
Hi everyone! I have problem using list control in visual c++. I tried to create a table which appears on a dialog window but when I run the executable on dialog appears only an empty "window" without the data I wrote. I used the "report view". Here is the code:
void CDataDialog::OnLvnItemchangedStoreItems(NMHDR *pNMHDR, LRESULT *pResult)
{LPNMLISTVIEW pNMLV = reinterpret\_cast(pNMHDR); // TODO: Add your control notification handler code here \*pResult = 0; //SetIcon(m\_hIcon, TRUE); // Set big icon //SetIcon(m\_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here // Ask Mfc to create/insert a column m\_StoreItems.InsertColumn( 0, // Rank/order of item L"ID", // Caption for this header LVCFMT\_LEFT, // Relative position of items under header 100); // Width of items under header m\_StoreItems.InsertColumn(1, L"Resistivity", LVCFMT\_CENTER, 80); m\_StoreItems.InsertColumn(2, L"Permeability", LVCFMT\_LEFT, 100); m\_StoreItems.InsertColumn(3, L"Rdc", LVCFMT\_LEFT, 80); int nItem; nItem = m\_StoreItems.InsertItem(0, L"1"); m\_StoreItems.SetItemText(nItem, 1, L"0.000869"); m\_StoreItems.SetItemText(nItem, 2, L"1"); m\_StoreItems.SetItemText(nItem, 3, L"0.09136"); nItem = m\_StoreItems.InsertItem(0, L"2"); m\_StoreItems.SetItemText(nItem, 1, L"0.0008603"); m\_StoreItems.SetItemText(nItem, 2, L"1"); m\_StoreItems.SetItemText(nItem, 3, L"0.09136"); nItem = m\_StoreItems.InsertItem(0, L"3"); m\_StoreItems.SetItemText(nItem, 1, L"0.000869"); m\_StoreItems.SetItemText(nItem, 2, L"1"); m\_StoreItems.SetItemText(nItem, 3, L"0.09136"); //return TRUE;
}
void CInputView::OnLinefeaturesData()
{
// TODO: Add your command handler code here
CInputDoc* pDoc = GetDocument();
CDataDialog DialogWindow;
DialogWindow.DoModal();}
-
Hi everyone! I have problem using list control in visual c++. I tried to create a table which appears on a dialog window but when I run the executable on dialog appears only an empty "window" without the data I wrote. I used the "report view". Here is the code:
void CDataDialog::OnLvnItemchangedStoreItems(NMHDR *pNMHDR, LRESULT *pResult)
{LPNMLISTVIEW pNMLV = reinterpret\_cast(pNMHDR); // TODO: Add your control notification handler code here \*pResult = 0; //SetIcon(m\_hIcon, TRUE); // Set big icon //SetIcon(m\_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here // Ask Mfc to create/insert a column m\_StoreItems.InsertColumn( 0, // Rank/order of item L"ID", // Caption for this header LVCFMT\_LEFT, // Relative position of items under header 100); // Width of items under header m\_StoreItems.InsertColumn(1, L"Resistivity", LVCFMT\_CENTER, 80); m\_StoreItems.InsertColumn(2, L"Permeability", LVCFMT\_LEFT, 100); m\_StoreItems.InsertColumn(3, L"Rdc", LVCFMT\_LEFT, 80); int nItem; nItem = m\_StoreItems.InsertItem(0, L"1"); m\_StoreItems.SetItemText(nItem, 1, L"0.000869"); m\_StoreItems.SetItemText(nItem, 2, L"1"); m\_StoreItems.SetItemText(nItem, 3, L"0.09136"); nItem = m\_StoreItems.InsertItem(0, L"2"); m\_StoreItems.SetItemText(nItem, 1, L"0.0008603"); m\_StoreItems.SetItemText(nItem, 2, L"1"); m\_StoreItems.SetItemText(nItem, 3, L"0.09136"); nItem = m\_StoreItems.InsertItem(0, L"3"); m\_StoreItems.SetItemText(nItem, 1, L"0.000869"); m\_StoreItems.SetItemText(nItem, 2, L"1"); m\_StoreItems.SetItemText(nItem, 3, L"0.09136"); //return TRUE;
}
void CInputView::OnLinefeaturesData()
{
// TODO: Add your command handler code here
CInputDoc* pDoc = GetDocument();
CDataDialog DialogWindow;
DialogWindow.DoModal();}
OnLvnItemchangedStoreItems
seems to be a LVN_ITEMCHANGED notification code (Windows)[^] handler. That is called whenever an item of a list control is changed but you are trying to create columns and add items there. But that handler is never called while you are not adding and changing items (and will produce a stack overflow or dead lock when adding items from within the handler). Move the code from the handler toCDataDialog::OnInitDialog
. That will populate the list and show it. -
OnLvnItemchangedStoreItems
seems to be a LVN_ITEMCHANGED notification code (Windows)[^] handler. That is called whenever an item of a list control is changed but you are trying to create columns and add items there. But that handler is never called while you are not adding and changing items (and will produce a stack overflow or dead lock when adding items from within the handler). Move the code from the handler toCDataDialog::OnInitDialog
. That will populate the list and show it.