Hi Everyone. I have a dialog box with a list control; populated with the contents of a database, an "Edit Trade" button and "Delete Trade" button. I select a item in the list control and then click "Edit Trade" This generates another dialog box, Edit Trade Dialog with controls populated with the data from the item in the list control. This control also has a "Edit" button. The general idea is that the user can change the data in the edit controls and then click the "Edit" button.
This is the problem. The data from any of the records I edit gets stored in the first record of the database and the original record I changed remains the same. I can't figure out why this is happening. I've checked the value of the item index from the list control. I selecting the correct item. I'm also using SetItemData() for each item in the list control. This value is being set to the TradeID for each record. This seems to be working fine as well.
Here is the code from FindDialog to populate the list control
Code:
void CFindDialog::OnButtonEdit()
{
//AfxMessageBox("You clicked the Edit Button");
CTransactionSet TmpSet;
CListCtrl* pList;
pList = &m_lcTradeList;
TmpSet.Open();
CEditTradeDialog TmpEdTrdDlg;
int nTransItemData;
//this will give us the item ID
this->nLcReturnValue = m_lcTradeList.GetNextItem(-1,LVNI_SELECTED);
int nItemIndex = this->nLcReturnValue;
CString strIndex;
strIndex.Format("the index %d", nItemIndex);
AfxMessageBox(strIndex);
if(this->nLcReturnValue == -1)
{
AfxMessageBox("You must select and entry");
}
else
{
CString y;
y.Format("The unique ID is %d" ,nItemIndex);
AfxMessageBox(y);
nTransItemData = m_lcTradeList.GetItemData(this->nLcReturnValue);
CString z;
z.Format("The TransactionID is %d",nTransItemData);
AfxMessageBox(z);
CString sel;
sel.Format("the TransactionID at Item %d is %d ", nItemIndex, nTransItemData);
AfxMessageBox(sel);
}
c_DeleteTrade.EnableWindow(false);
c_EditTrade.EnableWindow(false);
//TmpEdTrdDlg.SetListCtrl(pList,this->nLcReturnValue);
TmpEdTrdDlg.DoModal(nTransItemData);
}
here is the code from EditTradeDialog for the OnEdit() button this function should update the record whose fields populate the edit controls of this dialog box.
Code:
void CEditTradeDialog::OnEditTrade()
{
UpdateData();
CString strText;
strText.Format("The ID OnEditTrade is: %d", nTradeID);
AfxMessageBox(strText);
CTransactionSet TmpTransSet;
if(!TmpTransSet.IsOpen())
TmpTransSet.Open();
TmpTransSet.Edit();
TmpTransSet.m_Buyer = this->m_strBuyer;
TmpTransSet.m_Seller = this->m_strSeller;
TmpTransSet.m_BuyerBrokerNumber = atoi(this->m_strBuyerBrokerNumber);
TmpTransSet.m_BuyerBrokerCommission = atof(this->m_strBuyerBrokerComm);
TmpTransSet.m_SellerBrokerNumber = atoi(this->m_strSellerBrokerNumber);
TmpTransSet.m_SellerBrokerCommision = atof(this->m_strBuyerBrokerComm);
TmpTransSet.m_TradeDate = this->m_strTradeDate;
TmpTransSet.m_SettlementDate = this->m_strSettlementDate;
TmpTransSet.m_MaturityDate = this->m_strMaturityDate;
TmpTransSet.m_Amount = this->m_strAmount;
TmpTransSet.m_Rate = atof(this->m_strRate);
TmpTransSet.m_NumberOfDays = atoi(this->m_strNumberOfDays);
TmpTransSet.m_CollateralDescription = this->m_strSecurityDescription;
TmpTransSet.Update();
//TmpTransSet.UpdateItem(this->pList, this->nTradeID);
this->ClearContents();
CDialog::OnCancel();
}