Selection and Drag-Move

I’ve found what seems to be a quirk in selection. If I drag-select (rubberband?) and attempt to move all the nodes therein via LMB drag, the only thing that moves is the node that is under the mouse - the rest of the selection is deselected. However, this works if I CTRL-click each node individually rather than drag-selecting.

Is there a way to make both selection methods work so that I can move the whole group via LMB drag?

Is this in your app, or in the samples? If you have more than 1 object selected (via drag selection or otherwise), mouse-down-drag on any of the selected items will move the whole selection.

This is in my app. I’ll see if I can throw together a limited sample app that has the same behavior, unless you’ve got some suggestions.

Try our samples first. You should find that they follow standard Windows UI conventions.

Now, it is possible to mess up the default handling... possibly by overriding "mouse down" handling. If you have your own GoView class, look at the overrides you have.

I threw together a quick app that reproduces the problem. It seems that when I override SelectionObject, the behavior for drag-selection works differently than CTRL-selecting. I remember seeing that GoIconicNode overrides SelectionObject, but I was unable to reproduce the same behavior using GoIconicNodes. My code is below. Bear in mind this is hugely stripped-down from what’s in my app, but I’ve tried to reproduce most of the pertinent logic.

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

        GoDocument doc = new GoDocument();
        
        MyGoNode prevNode = new MyGoNode();
        prevNode.Location = new PointF(0, 0);
        doc.Add(prevNode);

        for (int i = 1; i < 6; i++)
        {
            MyGoNode newNode = new MyGoNode();
            
            newNode.Location = new PointF(i * 60, 0);

            GoLink lnk = new GoLink();
            newNode.MyPort.AddSourceLink(lnk);
            prevNode.MyPort.AddDestinationLink(lnk);
            
            doc.Add(newNode);
            doc.Add(lnk);

            prevNode = newNode;
        }


        this.goView1.Document = doc;
        this.goView1.RescaleToFit();
    }

    private class MyGoNode : GoNode
    {
        private GoRectangle _innerRect;
        private GoRectangle _outerRect;
        private GoPort _port;

        public MyGoNode()
        {
            this.Initializing = true;

            _innerRect = new GoRectangle();
            _innerRect.Size = new SizeF(20, 20);
            _innerRect.BrushColor = Color.Green;

            _outerRect = new GoRectangle();
            _outerRect.BrushColor = Color.Blue;

            _port = new GoPort();
            _port.Style = GoPortStyle.Rectangle;

            this.Add(_port);
            this.Add(_outerRect);
            this.Add(_innerRect);
            


            this.Initializing = false;
        }

        public override GoObject SelectionObject
        {
            get
            {
                return base.SelectionObject;
            }
        }

        public GoPort MyPort { get { return _port; } }

        public override void LayoutChildren(GoObject childchanged)
        {
            base.LayoutChildren(childchanged);

            RectangleF outerBounds = this._innerRect.Bounds;
            outerBounds.Inflate(4, 4);
            _outerRect.Bounds = outerBounds;
            _port.Bounds = _outerRect.Bounds;
        }
    }
}</font>

Your GoRectangles aren’t Selectable = false, so they get selection. But drag box selects the “Node”. So, if you select a bunch of these nodes with drag-box, you have a collection of Nodes selected. But, mouse down on a rectangle, and it checks to see “is this object part of the current selection?”… and the answer is “no”, because the Node is, not the rectangle.

adding "Selectable = false" to your 2 rectangles fixes this.
and you can then get rid of the SelectionObject override too, I think.

The SelectionObject override is important to my application logic. Setting Selectable = false negates the SelectionObject override. Any other ideas?

You want click-selection to select the same object as drag-box.
does adding the two selectable=false make things work? (it did for me).
I take it your real code doesn't point to base.SelectionObject?

Hah, that’s what it was. So, no, my real code doesn’t point to base.SelectionObject, and using Selectable=false with the correct SelectionObject override works both in my sample and in my app. Thanks for your help!

A follow-up:
Can you point me to somewhere in the docs where it talks about selection , especially in the context of a GoGroup with a SelectionObject override? The API docs for SelectionObject don’t go into much detail.

It’s mentioned several times in the User Guide. It’s documented in the API reference for GoObject.SelectionObject, and mentioned in several properties for GoNode.