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:
opulatePerson(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;
}
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:
{
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;
}