Delete Entry of access database from selecting it through list control vc++ 12
Implementing a ComapaniesDB Project, which is use to make entries of comapnies and details and on Add company to store those entry into access database. Now I am trying to add delete feature to it.
To delete User will select the Entry of company in List Control name COMPANYLIST , then after click on delete that particular entry will deleted.
For this I have to fire delete query. and to delete a particular row in list control I have to use where clause with the selected rows particular value.
if I select Company_ID then it goes into where clause to delete condition in query.
So First I have to get the selected value in List control For this I am trying following code:
Code:
void Cselect_product::OnItemchangedCOMPANYLIST(NMHDR* pNMHDR, LRESULT* pResult)
{
CListCtrl* pListCtrl = (CListCtrl *) GetDlgItem(IDC_COMPANYLIST);
POSITION pos = m_klist.GetFirstSelectedItemPosition ();
if (pos == NULL)
TRACE0 ("No items were selected! \n");
else
{
while (pos)
{
int nItem = m_klist.GetNextSelectedItem (pos);
TRACE1 ("Item %d was selected! \n", nItem);
//you could do your own processing on nItem here
strText = m_klist.GetItemText(nItem,0);
}
}
}
but it gives ignor,abort,retry type error.
after debigging I came to know that this is because of
Code:
CMFCListCtrl* pListCtrl = NULL;
if ((pListCtrl = (CMFCListCtrl*)this->GetDlgItem(IDC_COMPANYLIST)) != NULL)
{
int iIndex = -1;
while (++iIndex != sizeof(lpSampleDBListColumns) / sizeof(LVCOLUMN))
pListCtrl->InsertColumn(iIndex, &lpSampleDBListColumns[iIndex]);
m_wndCDBListCtrl.SubclassWindow(pListCtrl->GetSafeHwnd());
}
CCompaniesDBApp* pThisApp = NULL;
if ((pThisApp = (CCompaniesDBApp*)AfxGetApp()) != NULL)
if (pThisApp->ConnectToCDB(m_wndCDBListCtrl.GetConnectionString()))
m_wndCDBListCtrl.BindDataSource(pThisApp->m_pCompaniesDB);
m_wndCDBListCtrl.InitDBListCtrl();
m_wndCDBListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT);
This code in BOOL CCompaniesDBDlg::OnInitDialog() Method. which retrive all data from database on Dialogbox get load.
So Please tell me What modification should I do to delete perticulare selected data in list control, and changes also reflect into the database?
Plz find the attachment contain access database and project. (change database file path as per convenience)
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.