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)
Thanx
Last edited by kiwagh105@gmail.com; January 20th, 2016 at 02:24 AM.
Re: Delete Entry of access database from selecting it through list control vc++ 12
What is the type of lpSampleDBListColumns? Is this a pointer? If it is then sizeof(lpSampleDBListColumns) will be the size of a pointer type on your system (4 for 32 bit) irrespective of the amount of allocated memory pointed to by lpSampleDBListColumns.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
Re: Delete Entry of access database from selecting it through list control vc++ 12
Originally Posted by 2kaud
What is the type of lpSampleDBListColumns? Is this a pointer? If it is then sizeof(lpSampleDBListColumns) will be the size of a pointer type on your system (4 for 32 bit) irrespective of the amount of allocated memory pointed to by lpSampleDBListColumns.
Re: Delete Entry of access database from selecting it through list control vc++ 12
and what is the answer to Victor's question in post #2?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
Re: Delete Entry of access database from selecting it through list control vc++ 12
Originally Posted by VictorN
He igbnores about 90% of my posts/questions to him...
Sorry for let reply. When I click on Delete button Code for getting a text of selected item is executed. but as cursor came across to m_klist. selectediteam is give that error, after click on break icursoe goes on this line
if ((pListCtrl = (CMFCListCtrl*)this->GetDlgItem(IDC_COMPANYLIST)) != NULL)
Last edited by kiwagh105@gmail.com; January 21st, 2016 at 12:30 AM.
Re: Delete Entry of access database from selecting it through list control vc++ 12
Originally Posted by kiwagh105@gmail.com
Sorry for let reply. When I click on Delete button Code for getting a text of selected item is executed. but as cursor came across to m_klist. selectediteam is give that error, after click on break icursoe goes on this line
if ((pListCtrl = (CMFCListCtrl*)this->GetDlgItem(IDC_COMPANYLIST)) != NULL)
Could you now translate it into plain English?
Besides, it would be helpful if you explained what is the file containing the code snippet you showed, and where this file is.
* 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.