How to associate a row selected by ListControl with a specified path and file
-
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?
-
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?
-
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?
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
-
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
No,that is why I do not know how to code.
-
No,that is why I do not know how to code.
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
-
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
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(); }
-
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(); }
-
tianzhili4399 wrote:
But it fails when I debug
What fails, what errors do you see, what is LoadRbt supposed to do?
thank you,I have debug successfully! ;P