Thread: Updating a list control

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    17

    Updating a list control

    Hi,

    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
    Code:
    void CFindDialog::OnButtonEdit() 
    {
         //AfxMessageBox("You clicked the Edit Button");
    
         CTransactionSet TmpSet;
         CListCtrl* pList;
         pList = &m_lcTradeList;
         TmpSet.Open();
         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");
         }
         else
    
         {
    
              CString y;
              y.Format("The unique ID is %d" ,nItemIndex);
              AfxMessageBox(y);
    
              
              
              
              
              nTransID = m_lcTradeList.GetItemData(this->nLcReturnValue);
              CString z;
              z.Format("The TransactionID is %d",nTransID);
              AfxMessageBox(z);
    
    
              CString sel;
              sel.Format("the TransactionID at %d is %d ", nItemIndex, nTransID);
              AfxMessageBox(sel);
    
    
    
              
    
         }
    
    
                    //I thought of passing the address in the Domodal()
         TmpEdTrdDlg.DoModal(nTransID, pList);
    
         
    }
    This is the code for OnEditTrade() from the EditTrade dialog box


    Code:
    void CEditTradeDialog::OnEditTrade() 
    {
    
         UpdateData(TRUE);
    
         CTransactionSet TmpTransSet;
    
         
         if(!TmpTransSet.IsOpen())
              TmpTransSet.Open();
    
         TmpTransSet.Edit();
    
         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;
    
    
    
    
         TmpTransSet.Update();
    
         
    
         this->ClearContents();
    
         //TmpTransSet.UpdateItem(this->mpList);
    
         CDialog::OnCancel();
    
         
    
    
    
    
    
         
    }
    Below is the code I've started for UpdateItem() from CTransactionSet

    Code:
    void CTransactionSet::UpdateItem(CListCtrl *pList, int Item)
    {
    
         AfxMessageBox("In UpdateItem()");
    
         int nTrade = pList->GetItemData(Item);
    
         this->LocateTrade(nTrade);
    
         pList->SetItemText(Item,0,this->m_Buyer);
         pList->SetItemText(Item,1,this->m_Seller);
    
       
    
    
    
    
    
    }

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

    Kuphryn

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    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;

    pParent=(CFindDialog*)GetParent();
    if(pParent)
    pParent->m_VariableInParent

    (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