Accessing AcCustomize MultiSelectTreeview

Accessing AcCustomize MultiSelectTreeview

dennis
Advisor Advisor
647 Views
2 Replies
Message 1 of 3

Accessing AcCustomize MultiSelectTreeview

dennis
Advisor
Advisor

I found the control I want for a form which is under AcCustomize, the MultiSelectTreeview.  I was getting errors though and it appeared to be mismatched version numbers.

So I installed the AutoCAD-2020-SDK and now the version numbers are the same.

However, the problem persists.  The error says it cannot find the assembly ‘accoremgd’ version 23.1.0.0 (the 2020 version).  However, checking the properties it is right there.

My goal is to have selectable multiple (preferred only two, but got to get to multiple first) nodes on the tree view.  In my case, I do want to control a little too which two.  In this case, multiple parent nodes that can have multiple child nodes.  I want to be able to select the parent and one child, or two children under the same parent.

 

I think I can control that if I can get to Multiple selections first.AcCustomize error pic.png

 

0 Likes
Accepted solutions (1)
648 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

I have never thought of using this control from AcCustomize.dll. Seeing your question, I went for a try and did not have the issue of yours, well, at least for my very  simplified code. Here is what I did:

 

1. Start an AutoCAD .NET add-in dll project.

2. Add necessary AutoCAD .NET references, including acCustomize.dll, which also be configured as "Copy Local" to False.

3. Add a Win Form.

4. Since the controls in AcCustomize.dll cannot be added into VS Designer's Toolbox, the MultiSelectTreeview control is added to the win form by code - adding it to form in the form's constructor and populating it in Form_Load event handler, as shown below:

 

 

    public partial class Form1 : Form
    {
        private Autodesk.AutoCAD.Customization.MultiSelectTreeview _treeview = null;
        private TreeNode _rootNode = null;

        public Form1()
        {
            InitializeComponent();

            _treeview = new Autodesk.AutoCAD.Customization.MultiSelectTreeview();
            _treeview.Dock = DockStyle.Fill;
            _treeview.CheckBoxes = true;
            Controls.Add(_treeview);
        }

        private void PopulateTreeview()
        {
            _rootNode = new TreeNode("ROOT");

            AddChildren(_rootNode, "First Level");

            foreach (TreeNode node in _rootNode.Nodes)
            {
                AddChildren(node, "Second Level");
            }

            _treeview.Nodes.Add(_rootNode);
        }

        private void AddChildren(TreeNode node, string childName)
        {
            for (int i = 1; i <= 10; i++)
            {
                var text = childName + " " + i.ToString().PadLeft(2, '0');
                var nd = node.Nodes.Add(text);
            }   
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            PopulateTreeview();
        }
    }

 

 

5. show the form with MultiSelectTreeview with following command:

 

 

       [CommandMethod("MyForm")]
        public static void ShowFormWithTreeview()
        {
            using (var form = new Form1())
            {
                CadApp.ShowModalDialog(CadApp.MainWindow.Handle, form, false);
            }
        }

 

 

The modal form display the treeview correctly, which is no different from a regular Win form Treeview, except for each node having a default icon. I did not find a way to select multiple nodes, though (tried to hold either Ctrl, or Shift key while clicking nodes). See picture below:

MultiSelectTreeview.png

 

So, not sure where the error you have is from. I used Acad2021, VS2019, and target to .NET framework 4.8. But I do not see other later versions of AutoCAD/.NET framework would make it different.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3

dennis
Advisor
Advisor

Thanks Norman.  Your way worked.  In my case, the control does show up in the VS Toolbox and I was trying to drag-drop it from there.  Don't ask "how did it show up", I don't know, it was just there and I was exploring it.

0 Likes