CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2016
    Posts
    61

    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
    Attached Files Attached Files
    Last edited by kiwagh105@gmail.com; January 20th, 2016 at 02:24 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Delete Entry of access database from selecting it through list control vc++ 12

    Quote Originally Posted by kiwagh105@gmail.com View Post
    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?
    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    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!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    Join Date
    Jan 2016
    Posts
    61

    Re: Delete Entry of access database from selecting it through list control vc++ 12

    Quote Originally Posted by 2kaud View Post
    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

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    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!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Delete Entry of access database from selecting it through list control vc++ 12

    Quote Originally Posted by 2kaud View Post
    and what is the answer to Victor's question in post #2?
    He igbnores about 90% of my posts/questions to him...
    Victor Nijegorodov

  7. #7
    Join Date
    Jan 2016
    Posts
    61

    Re: Delete Entry of access database from selecting it through list control vc++ 12

    Quote Originally Posted by VictorN View Post
    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.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Delete Entry of access database from selecting it through list control vc++ 12

    Quote Originally Posted by kiwagh105@gmail.com View Post
    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.
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured