选中Tab控件单击事件,点击tab头,定位到导航栏的选项,为选中状态 ,DevExpress.XtraNavBar.NavBarControl 导航控件定位或选中状态 另导航的选项为选中状态.

         /// <summary>
        /// 选中Tab控件单击事件,点击tab头,定位到导航栏的选项,为选中状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void xtraTabControl1_Click(object sender, EventArgs e)
        {
            XtraTabControl obj = sender as XtraTabControl;
            DevExpress.XtraTab.XtraTabPage page = obj.SelectedTabPage;
            string switch_on = page.Tag.ToString(); //Tab,每个Tab的代码
            switch (switch_on)
            {
                case "2001":                    
                    SelectItem(switch_on);
                    break;
                case "2002":
                    SelectItem(switch_on);

                    break;

                case "2003":
                    SelectItem(switch_on);
                    break;

                case "2004":
                    SelectItem(switch_on);
                    break;

                case "2005":
                    SelectItem(switch_on);
                    break;

                case "2006":
                    SelectItem(switch_on);
                    break;

                case "2007":
                    SelectItem(switch_on);
                    break;
                
                default:
                    break;
            }

        }

        /// <summary>
        /// DevExpress.XtraNavBar.NavBarControl 导航控件定位或选中状态
        /// 另导航的选项为选中状态
        /// </summary>
        /// <param name="functionCode">Tag的代码,需要定位的导航项</param>
        private void SelectItem(string functionCode)
        {
            Console.WriteLine(functionCode);
            var length = this.navBarControl1.Groups.Count;
            for (int groupIndex = 0; groupIndex < length; groupIndex++)
            {
                var itemLength = this.navBarControl1.Groups[groupIndex].ItemLinks.Count;             

                for (int itemIndex = 0; itemIndex < itemLength; itemIndex++)
                {
                    var result = this.navBarControl1.Groups[groupIndex].ItemLinks[itemIndex].Item.Tag.ToString(); 

                    if (result == functionCode)
                    {
                        this.navBarControl1.Groups[groupIndex].Expanded = true;
                        navBarControl1.Groups[groupIndex].SelectedLinkIndex = itemIndex;                      

                        return;
                       
                    }                 

                }

            }
        }

 

posted @ 2017-05-14 12:08  一路来过  阅读(2066)  评论(0编辑  收藏  举报