private void btnPath_Click(object sender, EventArgs e)
        {
            ReportQueryItemPathResult reportQueryItemPathResult = ((ColorButton.ColorButton)sender).Tag as ReportQueryItemPathResult;

            ColorButton.ColorButton selected = ((ColorButton.ColorButton)sender);

            if (selectedBtnPath != null)
            {
                selectedBtnPath.IsSelected = false;
                selectedBtnPath.SetNormalState();
                selectedBtnPath.Invalidate();
            }

            selected.IsSelected = true;
            pnlPath.ScrollControlIntoView(selected);
            this.ScrollControlIntoView(selected);
            selectedBtnPath = selected;
        }
        void SelectNodeGraph()
        {
            // TODO: select nodes in selected Path
            Node selectedNode = gLocalViewer.SelectedObject as Node;

            if (selectedNode != null)
            {
                if (_prevSelectedNode != null)
                {
                    IGraphItem prevItem = _prevSelectedNode.UserData as GraphItem;
                    if (prevItem != null)
                    {
                        prevItem.IsSelected        = false;
                        _prevSelectedNode.UserData = prevItem;
                    }
                }

                GraphItem item = selectedNode.UserData as GraphItem;

                ColorButton.ColorButton nodeButton = new ColorButton.ColorButton();
                nodeButton.Text   = selectedNode.Id;
                nodeButton.Anchor = AnchorStyles.Top;
                nodeButton.Tag    = item;
                _selectedPath     = null;
                if (item.CurrentPathIndex > 0)
                {
                    DrawingHelper.SelectedPathItemUniqueID = item.QueryItem.Paths[item.CurrentPathIndex - 1].UniqueID;
                }
                DrawingHelper.SelectedNodeUniqueID = item.UniqueID;
                DrawingHelper.isEdgeSelected       = false;
                //ChangeSelectedFile(nodeButton, null);
                if (_pathItemClick != null)
                {
                    _pathItemClick(item.QueryItem.Paths[item.CurrentPathIndex - 1], null);
                }
                gLocalViewer.Refresh();
                gLocalViewer.ResumeLayout();
                gLocalViewer.Update();
                //_prevSelectedNode = selectedNode;
            }
        }
        public void SelectEdgeGraphByPath(GraphItem itemSource, GraphItem item, IGraphPath selectedPath)
        {
            if (itemSource.CurrentPathIndex > 0)
            {
                DrawingHelper.SelectedPathItem1UniqueID = itemSource.UniqueID;
            }

            if (item.CurrentPathIndex > 0)
            {
                DrawingHelper.SelectedPathItem2UniqueID = item.UniqueID;
            }
            DrawingHelper.SelectedNodeUniqueID = item.UniqueID;
            DrawingHelper.isEdgeSelected       = true;
            ColorButton.ColorButton nodeButton = new ColorButton.ColorButton();
            nodeButton.Text   = itemSource.ID;
            nodeButton.Anchor = AnchorStyles.Top;
            nodeButton.Tag    = item;
            _selectedPath     = selectedPath;
            gLocalViewer.Refresh();
            gLocalViewer.ResumeLayout();
            gLocalViewer.Update();
        }
        void SelectEdgeGraph()
        {
            try
            {
                // Fix problem with redrawing selected edge.(msagl bug)
                gLocalViewer.PanButtonPressed = true;
                Point pt = Cursor.Position;
                pt.X           += 120;
                pt.Y           += 100;
                Cursor.Position = pt;

                // TODO: select nodes in selected Path
                Edge selectedEdge = gLocalViewer.SelectedObject as Edge;
                if (selectedEdge != null)
                {
                    selectedEdge.Attr.Color     = Microsoft.Msagl.Drawing.Color.Black;
                    selectedEdge.Attr.LineWidth = 2;
                    selectedEdge.Attr.Weight    = 2;

                    Node sourceNode   = selectedEdge.SourceNode as Node;
                    Node selectedNode = sourceNode;
                    Node targetNode   = selectedEdge.TargetNode as Node;
                    selectedNode = targetNode;

                    GraphItem item = targetNode.UserData as GraphItem;
                    if (item == null)
                    {
                        return;
                    }

                    GraphItem itemSource = sourceNode.UserData as GraphItem;

                    if (itemSource.CurrentPathIndex > 0)
                    {
                        DrawingHelper.SelectedPathItem1UniqueID = itemSource.QueryItem.Paths[itemSource.CurrentPathIndex - 1].UniqueID;
                    }

                    if (item.CurrentPathIndex > 0)
                    {
                        DrawingHelper.SelectedPathItem2UniqueID = item.QueryItem.Paths[item.CurrentPathIndex - 1].UniqueID;
                    }
                    DrawingHelper.SelectedNodeUniqueID = item.UniqueID;
                    DrawingHelper.isEdgeSelected       = true;
                    ColorButton.ColorButton nodeButton = new ColorButton.ColorButton();
                    nodeButton.Text   = selectedNode.Id;
                    nodeButton.Anchor = AnchorStyles.Top;
                    nodeButton.Tag    = item;
                    _selectedPath     = selectedEdge.UserData as IGraphPath;
                    //ChangeSelectedFile(nodeButton, null);
                    if (_pathItemClick != null)
                    {
                        _pathItemClick(item.QueryItem.Paths[item.CurrentPathIndex - 1], null);
                    }
                    gLocalViewer.Refresh();
                    gLocalViewer.ResumeLayout();
                    gLocalViewer.Update();
                    _prevSelectedNode = selectedNode;
                }
            }
            finally
            {
                gLocalViewer.PanButtonPressed = false;
            }
        }
        /// <summary>
        /// Bind object data to form controls. Generate path sequance
        /// </summary>
        public void BindData(int index)
        {
            pnlPath.Controls.Clear();
            pnlPath.Width = 200;

            if (_queryItemResult.Paths == null)
            {
                return;
            }

            pnlPath.RowCount = _queryItemResult.Paths.Count;

            System.IO.Stream file      = Assembly.GetExecutingAssembly().GetManifestResourceStream("CxViewerAction.Resources.down.gif");
            System.IO.Stream fileEmpty = Assembly.GetExecutingAssembly().GetManifestResourceStream("CxViewerAction.Resources.empty.gif");


            for (int i = 0; i < _queryItemResult.Paths.Count; i++)
            {
                int row = 2 * i;
                ReportQueryItemPathResult path = _queryItemResult.Paths[i];

                ColorButton.ColorButton btnPath = new ColorButton.ColorButton();
                btnPath.ButtonStyle      = ColorButton.ColorButton.ButtonStyles.Rectangle;
                btnPath.SmoothingQuality = ColorButton.ColorButton.SmoothingQualities.HighQuality;
                btnPath.HoverColorA      = Color.WhiteSmoke;
                btnPath.HoverColorB      = Color.WhiteSmoke;
                btnPath.Text             = path.Name;
                //btnPath.Width = 100;
                //btnPath.Height = 40;
                btnPath.Anchor = AnchorStyles.Top;
                btnPath.Tag    = path;
                btnPath.Click += btnPath_Click;
                btnPath.Click += _pathButtonClickHandler;
                if (index == path.NodeId)
                {
                    btnPath.IsSelected = true;
                    selectedBtnPath    = btnPath;
                }

                pnlPath.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 40F));
                pnlPath.Controls.Add(btnPath, 0, row);
                pnlPath.RowStyles[row].Height = 40F;

                PictureBox imgDown = new PictureBox();
                imgDown.Width    = 16;
                imgDown.Height   = 16;
                imgDown.SizeMode = PictureBoxSizeMode.StretchImage;
                // Add arrow to all buttons instead of last
                if (i != _queryItemResult.Paths.Count - 1)
                {
                    imgDown.Image = Image.FromStream(file);
                }
                else
                {
                    //imgDown.Image = Image.FromStream(fileEmpty);
                }
                imgDown.Anchor = AnchorStyles.Top;

                pnlPath.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 23F));
                pnlPath.Controls.Add(imgDown, 0, row + 1);
                pnlPath.RowStyles[row + 1].Height = 20F;
            }

            this.AutoScrollMinSize = new System.Drawing.Size(200, _queryItemResult.Paths.Count * 61);
            pnlPath.Refresh();
            if (selectedBtnPath != null)
            {
                selectedBtnPath.Select();
                pnlPath.ScrollControlIntoView(selectedBtnPath);
                this.ScrollControlIntoView(selectedBtnPath);
            }
        }