Thread: CRecordset CListCtrl

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

    CRecordset CListCtrl

    Hi,

    I have a simple dialog based application with two edit boxes,a list control and an Add button. The
    OnAdd method updates the database as well as updates the list control with the info in the database. When I click the Add button it adds the previous edit box contents instead of the current. When I click the Add button again the right contents are added. Any insight into what I am doing wrong.

    Thanks,

    MPSoutine

    Dialog OnAdd function:

    void CYadbeDlg::OnAdd()
    {
    // TODO: Add your control notification handler code here
    UpdateData();//Call this member function to initialize data in a
    //dialog box, or to retrieve and validate dialog data.


    CDemoset tmp;
    tmp.Add(m_Text);


    tmp.PopulatePerson(&m_lcPerson);


    }


    The Add to recordset function:

    int CDemoset::Add(LPCTSTR Text)
    {
    //locate a new unique ID
    if(IsOpen())//Call this member function to determine if the recordset is already open.
    {
    //AfxMessageBox("DBOpen in CDemoset::Add()");
    Close();
    }
    //else
    //AfxMessageBox("DB Not open in CDemoset::Add()");

    m_strSort = "MyID";
    m_strFilter.Empty();//Makes this CString object an empty string and frees memory as appropriate.

    Open();

    int NewID;

    if(IsEOF())
    {
    //AfxMessageBox("IsEOF is true in CDemoset::Add()");
    NewID = 1;
    }
    else
    {
    //AfxMessageBox("IsEOF is not true in CDemoset::Add()");
    NewID = m_MyID + 1;
    }

    //Place record in AddNew mode
    AddNew();

    m_MyID = NewID;
    m_MyText = Text;

    Update();//Call this member function after a call to the AddNew or
    //Edit member function. This call is required to complete
    //the AddNew or Edit operation.





    return 0;


    }

    Populate list control function


    int CDemoset::PopulatePerson(CListCtrl *pListControl)
    {

    pListControl->DeleteAllItems();

    if(IsOpen())
    {
    //AfxMessageBox("DB is open");
    MoveFirst();//Call this member function to make the first
    //record in the first rowset the current record.
    }
    else
    Open();



    int Index;
    while(!IsEOF())
    {
    Index = pListControl->InsertItem(pListControl->GetItemCount(),m_MyText);//GetItemCount()Retrieves the number of items in a list view control.
    pListControl->SetItemText(Index,1,m_MyText);
    MoveNext();
    }



    return 0;

    }

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Read this.

    First, check that the DDX code is working as expected. Put a break point in OnAdd() and check that m_Text contains what you typed in the edit box. If that works, then you know the problem is with you DB code.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# Version of MFC CListCtrl
    By gotclout in forum C# Programming
    Replies: 6
    Last Post: 06-18-2007, 08:57 AM
  2. MFC insert into access db (CRecordset)
    By maes in forum Windows Programming
    Replies: 11
    Last Post: 12-23-2003, 08:49 PM
  3. CListCtrl and Arbitrary Data :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 01-25-2003, 01:21 AM
  4. CListCtrl List Style :: MFC
    By kuphryn in forum Windows Programming
    Replies: 4
    Last Post: 11-18-2002, 09:37 AM
  5. CListCtrl in Dialog Box & Select :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 06-08-2002, 12:05 AM