troubles on exchanging data between dialog
-
hi all... want to exchange a list control data between dialogs, but when I tried it, it failed and I don't know why..can anyone help? //I initialize the 2nd dialog at the 1st dialog class CAddNeighborsDialog* dlg = new CAddNeighborsDialog; int count = 0; /*inserting data to m_listAddNeighbors(CListCtrl data type)in dialog 2 from m_strData(CStringArray data type)*/ while(count*29m_listAddNeighbors.GetItemCount(); dlg->m_listAddNeighbors.InsertItem(nItem,m_strData.GetAt((count*29)+10)); dlg->m_listAddNeighbors.SetItemText(nItem,1,m_strData.GetAt((count*29)+1)); count++; } if(dlg->DoModal() == IDOK) { //I try to test it using message box, but the message box shows nothing MessageBox(dlg->m_listAddNeighbor.GetItemText(0,1)); } } pls help... thx
-
hi all... want to exchange a list control data between dialogs, but when I tried it, it failed and I don't know why..can anyone help? //I initialize the 2nd dialog at the 1st dialog class CAddNeighborsDialog* dlg = new CAddNeighborsDialog; int count = 0; /*inserting data to m_listAddNeighbors(CListCtrl data type)in dialog 2 from m_strData(CStringArray data type)*/ while(count*29m_listAddNeighbors.GetItemCount(); dlg->m_listAddNeighbors.InsertItem(nItem,m_strData.GetAt((count*29)+10)); dlg->m_listAddNeighbors.SetItemText(nItem,1,m_strData.GetAt((count*29)+1)); count++; } if(dlg->DoModal() == IDOK) { //I try to test it using message box, but the message box shows nothing MessageBox(dlg->m_listAddNeighbor.GetItemText(0,1)); } } pls help... thx
I am not sure about the rest of your code, but... firebolt77 wrote: //I try to test it using message box, but the message box shows nothing MessageBox(dlg->m_listAddNeighbor.GetItemText(0,1)); This is definitely not going to work, because all controls on a dialog die, when DoModal() comes back. Therefore, you are using GetItemText() from a list control that does not exist. You can try this: Keep a list. E.g, CStringArray variable in your dialog, then override OnOK(), and fill this CStringArray with the items etc in OnOK(). Then later, after DoModal(), you can access this list, and it will still contain the data. this is this.
-
hi all... want to exchange a list control data between dialogs, but when I tried it, it failed and I don't know why..can anyone help? //I initialize the 2nd dialog at the 1st dialog class CAddNeighborsDialog* dlg = new CAddNeighborsDialog; int count = 0; /*inserting data to m_listAddNeighbors(CListCtrl data type)in dialog 2 from m_strData(CStringArray data type)*/ while(count*29m_listAddNeighbors.GetItemCount(); dlg->m_listAddNeighbors.InsertItem(nItem,m_strData.GetAt((count*29)+10)); dlg->m_listAddNeighbors.SetItemText(nItem,1,m_strData.GetAt((count*29)+1)); count++; } if(dlg->DoModal() == IDOK) { //I try to test it using message box, but the message box shows nothing MessageBox(dlg->m_listAddNeighbor.GetItemText(0,1)); } } pls help... thx
I imagine that it's because the dialog it's been destroyed after closing it: add a breakpoint into OnDestroy message handler in your dialog's class. It doesn't fail because it still exists but it has no value. You should retrieve the data before it's destroyed but it depends on how/where you have defined the dialogs. Marc Soleda. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
-
I am not sure about the rest of your code, but... firebolt77 wrote: //I try to test it using message box, but the message box shows nothing MessageBox(dlg->m_listAddNeighbor.GetItemText(0,1)); This is definitely not going to work, because all controls on a dialog die, when DoModal() comes back. Therefore, you are using GetItemText() from a list control that does not exist. You can try this: Keep a list. E.g, CStringArray variable in your dialog, then override OnOK(), and fill this CStringArray with the items etc in OnOK(). Then later, after DoModal(), you can access this list, and it will still contain the data. this is this.
thx...it works... Thx for the reply...
-
hi all... want to exchange a list control data between dialogs, but when I tried it, it failed and I don't know why..can anyone help? //I initialize the 2nd dialog at the 1st dialog class CAddNeighborsDialog* dlg = new CAddNeighborsDialog; int count = 0; /*inserting data to m_listAddNeighbors(CListCtrl data type)in dialog 2 from m_strData(CStringArray data type)*/ while(count*29m_listAddNeighbors.GetItemCount(); dlg->m_listAddNeighbors.InsertItem(nItem,m_strData.GetAt((count*29)+10)); dlg->m_listAddNeighbors.SetItemText(nItem,1,m_strData.GetAt((count*29)+1)); count++; } if(dlg->DoModal() == IDOK) { //I try to test it using message box, but the message box shows nothing MessageBox(dlg->m_listAddNeighbor.GetItemText(0,1)); } } pls help... thx
firebolt77 wrote: CAddNeighborsDialog* dlg = new CAddNeighborsDialog; Why do this, especially when there is no
delete
shown? It just ties up the memory manager unnecessarily.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb