Thread: Updating a list control

  1. #1
    Registered User
    Join Date
    Mar 2003

    Updating a list control


    I'll give an overview of my program. I'm using MFC and an Access database. In my FormView class the user clicks the "Find Trade" button. This generates a "FindTrade" dialog box which has a list control populated with the contents of a database as well as an "Edit" button.

    The user selects an item in the list control and then clicks the "Edit" button. This generates an "Edit Trade" dialog box with edit controls populated with the field contents of the record selected in the list control. Once the user edits any data in the edit controls the "EditTrade" button is clicked. This updates the record in the database just fine.

    What I would like to is have a function in my CTransactionSet class called UpDateItem() that will update the list control in "FindTrade" dialog with the record that was edited. The problem I'm having is trying to figure out how to pass the address of the list control in my "Find Trade" dialog box to a function, UpdateItem() in my Recordset class.

    I thought of passing it the address in the DoModal() for CEditTradeDialog. To be honest I'm not completely how to pass the address of the list control.

    Below is the code for OnButtonEdit() from FindTrade dialog box
    void CFindDialog::OnButtonEdit() 
         //AfxMessageBox("You clicked the Edit Button");
         CTransactionSet TmpSet;
         CListCtrl* pList;
         pList = &m_lcTradeList;
         CEditTradeDialog TmpEdTrdDlg;
         int nTransID;
         this->nLcReturnValue = m_lcTradeList.GetNextItem(-1,LVNI_SELECTED);
         int nItemIndex = this->nLcReturnValue;
         if(this->nLcReturnValue == -1)
              AfxMessageBox("You must select and entry");
              CString y;
              y.Format("The unique ID is %d" ,nItemIndex);
              nTransID = m_lcTradeList.GetItemData(this->nLcReturnValue);
              CString z;
              z.Format("The TransactionID is %d",nTransID);
              CString sel;
              sel.Format("the TransactionID at %d is %d ", nItemIndex, nTransID);
                    //I thought of passing the address in the Domodal()
         TmpEdTrdDlg.DoModal(nTransID, pList);
    This is the code for OnEditTrade() from the EditTrade dialog box

    void CEditTradeDialog::OnEditTrade() 
         CTransactionSet TmpTransSet;
         TmpTransSet.m_Buyer = m_strBuyer;
         TmpTransSet.m_Seller = m_strSeller;
         TmpTransSet.m_BuyerBrokerNumber = atoi(m_strBuyerBrokerNumber);
         TmpTransSet.m_BuyerBrokerCommission = atof(m_strBuyerBrokerComm);
         TmpTransSet.m_SellerBrokerNumber = atoi(m_strSellerBrokerNumber);
         TmpTransSet.m_SellerBrokerCommision = atof(m_strBuyerBrokerComm);
         TmpTransSet.m_TradeDate = m_strTradeDate;
         TmpTransSet.m_SettlementDate = m_strSettlementDate;
         TmpTransSet.m_MaturityDate = m_strMaturityDate;
         TmpTransSet.m_Amount = m_strAmount;
         TmpTransSet.m_Rate = atof(m_strRate);
         TmpTransSet.m_NumberOfDays = atoi(m_strNumberOfDays);
         TmpTransSet.m_CollateralDescription = m_strSecurityDescription;
    Below is the code I've started for UpdateItem() from CTransactionSet

    void CTransactionSet::UpdateItem(CListCtrl *pList, int Item)
         AfxMessageBox("In UpdateItem()");
         int nTrade = pList->GetItemData(Item);

  2. #2
    Registered User
    Join Date
    Nov 2001
    One solution is messages. Send a message from the dialog window to the view window and have it update the list control.


  3. #3
    train spotter
    Join Date
    Aug 2001
    near a computer
    as kuphryn says send a message

    or if the combo is a member variable of the CFindDialog

    Use something like in the edit dlg
    CFindDialog *pParent=NULL;


    (forgive my C style casts)

    or as the dlg is modal and so nothing else happens until it is dealt with, just update the combo's list after the dlg has closed

    ie after

    TmpEdTrdDlg.DoModal(nTransID, pList);

    Try sending a diff return value to tell you if the user did edit or just canceled.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pleas take a look & give a critique
    By sh3rpa in forum C++ Programming
    Replies: 14
    Last Post: 10-19-2007, 10:01 PM
  2. circular doubly linked list help
    By gunnerz in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2007, 08:38 PM
  3. urgent help please...
    By peter_hii in forum C++ Programming
    Replies: 11
    Last Post: 10-30-2006, 06:37 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Linked List
    By jpipitone in forum C Programming
    Replies: 4
    Last Post: 03-30-2003, 09:27 PM