1 Attachment(s)
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
Re: Delete Entry of access database from selecting it through list control vc++ 12
Quote:
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.
And what line of this code snippet causes the problem?
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.
Re: Delete Entry of access database from selecting it through list control vc++ 12
Quote:
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.
lpSampleDBListColumns is a:
static LVCOLUMN lpSampleDBListColumns[] =
{
{ LVCF_TEXT | LVCF_WIDTH, 0, 170, _T("Category"), 256, 0 },
{ LVCF_TEXT | LVCF_WIDTH, 0, 170, _T("Company Name"), 256, 0 },
{ LVCF_TEXT | LVCF_WIDTH, 0, 250, _T("Address 1"), 256, 0 },
{ LVCF_TEXT | LVCF_WIDTH, 0, 100, _T("Address 2"), 256, 0 },
{ LVCF_TEXT | LVCF_WIDTH, 0, 100, _T("Address 3"), 256, 0 },
{ LVCF_TEXT | LVCF_WIDTH, 0, 60, _T("Model"), 256, 0 },
{ LVCF_TEXT | LVCF_WIDTH, 0, 60, _T("OrderNo"), 256, 0 },
{ LVCF_TEXT | LVCF_WIDTH, 0, 60, _T("Logo"), 256, 0 },
{LVCF_TEXT | LVCF_WIDTH, 0, 60, _T("UUT Name"), 256, 0 }};
I attached complete project. plz see attachment
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?
Re: Delete Entry of access database from selecting it through list control vc++ 12
Quote:
Originally Posted by
2kaud
and what is the answer to Victor's question in post #2?
He igbnores about 90% of my posts/questions to him... :sick:
Re: Delete Entry of access database from selecting it through list control vc++ 12
Quote:
Originally Posted by
VictorN
He igbnores about 90% of my posts/questions to him... :sick:
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)
Re: Delete Entry of access database from selecting it through list control vc++ 12
Quote:
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.