Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to associate a row selected by ListControl with a specified path and file

How to associate a row selected by ListControl with a specified path and file

Scheduled Pinned Locked Moved C / C++ / MFC
questionregexhelptutorial
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tianzhili4399
    wrote on last edited by
    #1

    The function I need to implement is to first select a row in the ListControl, and then press the "Import" button, the program will import the file corresponding to the pre-set corresponding path of this row. I have written an import function, just need to provide the path and name corresponding to the file you want to import. The problem is that I don't know how to match the selected line with the pre-set path and file, because there are too many files and paths (at least 20) to be set in advance, and listcontrol has the same number of lines and files as the number of files. The point of my problem is that I don't know how to get the number of any selected row to associate it with the corresponding path and file. All I know is to associate any row selected by the ListControl with only one of the specified paths and files. Here are my codes:

    void RobotmodelPre::OnBnClickedInputmodel()
    {

    CDocTemplate\* pDocTempl;
    POSITION pos=AfxGetApp()->GetFirstDocTemplatePosition();
    pDocTempl=AfxGetApp()->GetNextDocTemplate(pos);
    POSITION posDoc=pDocTempl->GetFirstDocPosition();
    if (posDoc!=NULL)
    {
    	m\_pDoc=(CRobotAppDoc\*)pDocTempl->GetNextDoc(posDoc);	
    } 
    else
    {
    	m\_pDoc=NULL;
    	AfxMessageBox("FAIL!");
    	return;
    }
    
    CString filePath1 = "D:\\\\robot\_new\\\\Data\\\\4kg\_simplified\\\\SR4\_SIASUN.rbt";
    CString folderPath1 ="D:\\\\robot\_new\\\\Data\\\\4kg\_simplified";
    
    CWaitCursor	cur;
    XObject obj;
    bool bIsRobotLoad = false, bIsObjectLoad = false, bIsWorkPieceLoad = false, blsToolLoad = false;
    int iObjSize = m\_pDoc->m\_vObj.size();
    int iRobot = -1, iObj = -1;
    CMainFrame\* pMainFrame = (CMainFrame\*)AfxGetMainWnd();
    if( m\_pDoc->LoadRbt(filePath1,folderPath1))
    		{
    			bIsRobotLoad = true;
    			iRobot=  m\_pDoc->m\_vRobot.size()-1;
    			pMainFrame->m\_wndModelTreeView.DisplayRobotTree();
    		}
    

    }

    Among them, the "LoadRbt" function only needs to provide two parameters. The debugging result of this code is that no matter which line is selected, the same file will be imported (the rbt file is a file I customize). How can I select different lines and import different files?

    L D 2 Replies Last reply
    0
    • T tianzhili4399

      The function I need to implement is to first select a row in the ListControl, and then press the "Import" button, the program will import the file corresponding to the pre-set corresponding path of this row. I have written an import function, just need to provide the path and name corresponding to the file you want to import. The problem is that I don't know how to match the selected line with the pre-set path and file, because there are too many files and paths (at least 20) to be set in advance, and listcontrol has the same number of lines and files as the number of files. The point of my problem is that I don't know how to get the number of any selected row to associate it with the corresponding path and file. All I know is to associate any row selected by the ListControl with only one of the specified paths and files. Here are my codes:

      void RobotmodelPre::OnBnClickedInputmodel()
      {

      CDocTemplate\* pDocTempl;
      POSITION pos=AfxGetApp()->GetFirstDocTemplatePosition();
      pDocTempl=AfxGetApp()->GetNextDocTemplate(pos);
      POSITION posDoc=pDocTempl->GetFirstDocPosition();
      if (posDoc!=NULL)
      {
      	m\_pDoc=(CRobotAppDoc\*)pDocTempl->GetNextDoc(posDoc);	
      } 
      else
      {
      	m\_pDoc=NULL;
      	AfxMessageBox("FAIL!");
      	return;
      }
      
      CString filePath1 = "D:\\\\robot\_new\\\\Data\\\\4kg\_simplified\\\\SR4\_SIASUN.rbt";
      CString folderPath1 ="D:\\\\robot\_new\\\\Data\\\\4kg\_simplified";
      
      CWaitCursor	cur;
      XObject obj;
      bool bIsRobotLoad = false, bIsObjectLoad = false, bIsWorkPieceLoad = false, blsToolLoad = false;
      int iObjSize = m\_pDoc->m\_vObj.size();
      int iRobot = -1, iObj = -1;
      CMainFrame\* pMainFrame = (CMainFrame\*)AfxGetMainWnd();
      if( m\_pDoc->LoadRbt(filePath1,folderPath1))
      		{
      			bIsRobotLoad = true;
      			iRobot=  m\_pDoc->m\_vRobot.size()-1;
      			pMainFrame->m\_wndModelTreeView.DisplayRobotTree();
      		}
      

      }

      Among them, the "LoadRbt" function only needs to provide two parameters. The debugging result of this code is that no matter which line is selected, the same file will be imported (the rbt file is a file I customize). How can I select different lines and import different files?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You have hardcoded your file names instead of getting the selected item from the ListBox.

      1 Reply Last reply
      0
      • T tianzhili4399

        The function I need to implement is to first select a row in the ListControl, and then press the "Import" button, the program will import the file corresponding to the pre-set corresponding path of this row. I have written an import function, just need to provide the path and name corresponding to the file you want to import. The problem is that I don't know how to match the selected line with the pre-set path and file, because there are too many files and paths (at least 20) to be set in advance, and listcontrol has the same number of lines and files as the number of files. The point of my problem is that I don't know how to get the number of any selected row to associate it with the corresponding path and file. All I know is to associate any row selected by the ListControl with only one of the specified paths and files. Here are my codes:

        void RobotmodelPre::OnBnClickedInputmodel()
        {

        CDocTemplate\* pDocTempl;
        POSITION pos=AfxGetApp()->GetFirstDocTemplatePosition();
        pDocTempl=AfxGetApp()->GetNextDocTemplate(pos);
        POSITION posDoc=pDocTempl->GetFirstDocPosition();
        if (posDoc!=NULL)
        {
        	m\_pDoc=(CRobotAppDoc\*)pDocTempl->GetNextDoc(posDoc);	
        } 
        else
        {
        	m\_pDoc=NULL;
        	AfxMessageBox("FAIL!");
        	return;
        }
        
        CString filePath1 = "D:\\\\robot\_new\\\\Data\\\\4kg\_simplified\\\\SR4\_SIASUN.rbt";
        CString folderPath1 ="D:\\\\robot\_new\\\\Data\\\\4kg\_simplified";
        
        CWaitCursor	cur;
        XObject obj;
        bool bIsRobotLoad = false, bIsObjectLoad = false, bIsWorkPieceLoad = false, blsToolLoad = false;
        int iObjSize = m\_pDoc->m\_vObj.size();
        int iRobot = -1, iObj = -1;
        CMainFrame\* pMainFrame = (CMainFrame\*)AfxGetMainWnd();
        if( m\_pDoc->LoadRbt(filePath1,folderPath1))
        		{
        			bIsRobotLoad = true;
        			iRobot=  m\_pDoc->m\_vRobot.size()-1;
        			pMainFrame->m\_wndModelTreeView.DisplayRobotTree();
        		}
        

        }

        Among them, the "LoadRbt" function only needs to provide two parameters. The debugging result of this code is that no matter which line is selected, the same file will be imported (the rbt file is a file I customize). How can I select different lines and import different files?

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Is the path/file part of the ListControl contents?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        T 1 Reply Last reply
        0
        • D David Crow

          Is the path/file part of the ListControl contents?

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          T Offline
          T Offline
          tianzhili4399
          wrote on last edited by
          #4

          No,that is why I do not know how to code.

          D 1 Reply Last reply
          0
          • T tianzhili4399

            No,that is why I do not know how to code.

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Then I would suggest calling SetItemData() after each item is added to the control. Then when an item in the list control is clicked, use the index/pos number provided to call GetIemData().

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            T 1 Reply Last reply
            0
            • D David Crow

              Then I would suggest calling SetItemData() after each item is added to the control. Then when an item in the list control is clicked, use the index/pos number provided to call GetIemData().

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              T Offline
              T Offline
              tianzhili4399
              wrote on last edited by
              #6

              wow,thank you for your advice!I will try later! I tried to solve the problem myself by means of using "CStringArray".But it fails when I debug and I do not know the reason.Would you please tell me the bug? Here are the addition codes:

              **CStringArray filePaths;
              CStringArray folderPaths;
              
              filePaths.Add("D:\\\\robot\_new\\\\Data\\\\4kg\_simplified\\\\SR4\_SIASUN.rbt");
              filePaths.Add("D:\\\\robot\_new\\\\Data\\\\IRB4400\\\\IRB4400 m.rbt");
              folderPaths.Add("D:\\\\robot\_new\\\\Data\\\\4kg\_simplified");
              folderPaths.Add("D:\\\\robot\_new\\\\Data\\\\IRB4400");**
              
              CWaitCursor	cur;
              XObject obj;
              bool bIsRobotLoad = false, bIsObjectLoad = false, bIsWorkPieceLoad = false, blsToolLoad = false;
              int iObjSize = m\_pDoc->m\_vObj.size();
              int iRobot = -1, iObj = -1;
              CMainFrame\* pMainFrame = (CMainFrame\*)AfxGetMainWnd();
              if( m\_pDoc->LoadRbt(**filePaths\[nId-1\],folderPaths\[nId-1\]**)) //here is the change
              	{
              		bIsRobotLoad = true;
              		iRobot=  m\_pDoc->m\_vRobot.size()-1;
              		pMainFrame->m\_wndModelTreeView.DisplayRobotTree();
              	}
              
              L 1 Reply Last reply
              0
              • T tianzhili4399

                wow,thank you for your advice!I will try later! I tried to solve the problem myself by means of using "CStringArray".But it fails when I debug and I do not know the reason.Would you please tell me the bug? Here are the addition codes:

                **CStringArray filePaths;
                CStringArray folderPaths;
                
                filePaths.Add("D:\\\\robot\_new\\\\Data\\\\4kg\_simplified\\\\SR4\_SIASUN.rbt");
                filePaths.Add("D:\\\\robot\_new\\\\Data\\\\IRB4400\\\\IRB4400 m.rbt");
                folderPaths.Add("D:\\\\robot\_new\\\\Data\\\\4kg\_simplified");
                folderPaths.Add("D:\\\\robot\_new\\\\Data\\\\IRB4400");**
                
                CWaitCursor	cur;
                XObject obj;
                bool bIsRobotLoad = false, bIsObjectLoad = false, bIsWorkPieceLoad = false, blsToolLoad = false;
                int iObjSize = m\_pDoc->m\_vObj.size();
                int iRobot = -1, iObj = -1;
                CMainFrame\* pMainFrame = (CMainFrame\*)AfxGetMainWnd();
                if( m\_pDoc->LoadRbt(**filePaths\[nId-1\],folderPaths\[nId-1\]**)) //here is the change
                	{
                		bIsRobotLoad = true;
                		iRobot=  m\_pDoc->m\_vRobot.size()-1;
                		pMainFrame->m\_wndModelTreeView.DisplayRobotTree();
                	}
                
                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                tianzhili4399 wrote:

                But it fails when I debug

                What fails, what errors do you see, what is LoadRbt supposed to do?

                T 1 Reply Last reply
                0
                • L Lost User

                  tianzhili4399 wrote:

                  But it fails when I debug

                  What fails, what errors do you see, what is LoadRbt supposed to do?

                  T Offline
                  T Offline
                  tianzhili4399
                  wrote on last edited by
                  #8

                  thank you,I have debug successfully! ;P

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups