Hi all.
I'm coding a project in visuel C#, and in VBA.
The connection between the two is made with a COM object.
I have created a TreeView in VBA with the librairie MSCOMCTL. And i want to send this TreeView Object to C#
The thing is that C# windows Forms TreeView seems to be not compatible with VBA MSCOMCTL treeView.
Is there any tips or idea to fix this ?
any help is welcome !
I'm coding a project in visuel C#, and in VBA.
The connection between the two is made with a COM object.
I have created a TreeView in VBA with the librairie MSCOMCTL. And i want to send this TreeView Object to C#
The thing is that C# windows Forms TreeView seems to be not compatible with VBA MSCOMCTL treeView.
Is there any tips or idea to fix this ?
any help is welcome !

VulpesRank #55 · 29.2K reputationPosted Aug 4, 2011, 5:39 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 2, 2011, 6:46 AM EDT
If you're using a 64-bit OS, then you may have problems using MSCOMCTL.OCX.
If relevant, check out this thread for a possible solution (http://www.c-sharpcorner.com/Forums/Thread/111898/mscomctl-ocx-raising-exception-in-64-bit-os-win-7.aspx).
plop plop17 reputationPosted Aug 2, 2011, 7:27 AM EDT
Yes, i tried using the MSCOMCTL TreeView in my C# application. But i got issues with MSCOMCTL method.
i'm trying to resolve that since 2 days with any improvement.
I think that C# can't understand parameters of MSCOMCTL methods. For exemple, C# does not accept any argument for : myTreeView.Nodes.Add or at least has issues with it at compilation.
Is there any solution to build a MSCOMCTL treeview cleanly in C# ? i begin doubt about it !
VulpesRank #55 · 29.2K reputationPosted Aug 2, 2011, 8:11 AM EDT
plop plop17 reputationPosted Aug 2, 2011, 8:54 AM EDT
foreach(PARTNERSHIP part in Partener)
{
object nullissimo = Type.Missing;
object CodePart = part.PARTNERSHIP_CODE.ToString();
object RelationShip = mscomctl.TreeRelationshipConstants.tvwFirst;
object rootTitle = part.PARTNERSHIP_NAME.ToString();
myTree.Nodes.Add(ref CodePart, ref RelationShip, ref CodePart, ref rootTitle, ref nullissimo, ref nullissimo);
}
myTree is a mscomctl.TreeViewClass
The error returned for the add method is : Element not found
I'm using Visual studio 2008, Microsoft Office 2003 on Windows XP.
Thank you again for your help.
VulpesRank #55 · 29.2K reputationPosted Aug 2, 2011, 1:03 PM EDT
Are you able to determine which parameter is throwing the error?
I suspect it will be first one (Relative) and couldn't understand why it was the same as the third one (Key).
plop plop17 reputationPosted Aug 3, 2011, 10:13 PM EDT
I changed the paramaters like you suggested :
myTree.Nodes.Add(ref id, ref RelationShip, ref CodePart, ref rootTitle, ref nullissimo1, ref nullissimo2);
Now the returned error is : Element not found.
VulpesRank #55 · 29.2K reputationPosted Aug 4, 2011, 2:53 AM EDT
If it is an index ID, I'd try using its key instead and see if the element can then be found.
plop plop17 reputationPosted Aug 4, 2011, 4:22 AM EDT
plop plop17 reputationPosted Aug 4, 2011, 6:50 AM EDT
that's work perfectly ... but this solution leads to another question :
i'm trying to add an imageList to my treeview. Above the code :
object bt = Bitmap.FromFile("C:\\Documents and Settings\\...\\Incubation-16.ico");
object index = 0;
object name = "AM-Company";
mscomctl.ImageListClass status = new mscomctl.ImageListClass();
status.ListImages.Add(ref index,ref name,ref bt);
myTree.ImageList = status;
The error returned is : Invalid picture
I tried to load the picture with other methods ... the same error is displayed. If you have any solution to that i'm interested !
Thank you again ! thank you a lot !!!
VulpesRank #55 · 29.2K reputationPosted Aug 4, 2011, 7:26 AM EDT
Is there an Image class, or similar, included in MSCOMCTL.DLL that you could use instead?
VulpesRank #55 · 29.2K reputationPosted Aug 4, 2011, 7:51 AM EDT
plop plop17 reputationPosted Aug 8, 2011, 1:44 AM EDT
But look at my code, it's what i did. I can't create an instance of listImages ... it has no contructor, plus it's a imageKistClass method.
In the link you found, they use a "loadPicture" method but it seems that there is no equivalent method to that ... or at least i can't find it ... that's why i use the "Bitmap.FromFile" method which i think is the cause of my issue.
VulpesRank #55 · 29.2K reputationPosted Aug 8, 2011, 2:40 AM EDT
plop plop17 reputationPosted Aug 8, 2011, 4:07 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 8, 2011, 4:30 AM EDT
Could you in fact do this or do you need to add the images to the control dynamically?
plop plop17 reputationPosted Aug 8, 2011, 5:45 AM EDT
So i would rather add the images at "compile-time".
In fact, i'm not sure i can add images at run-time with a COM object ?
VulpesRank #55 · 29.2K reputationPosted Aug 8, 2011, 5:56 AM EDT
If that works, you can then associate the ImageList object with the TreeView rather than trying to create your own programatically.
The only way to add images at runtime appears to be to use the LoadPicture() function which you mentioned earlier. However, I can't think of any way in which we can use that from C#.