2012-09-11 31 views
0

我需要的是非常自定義的情況。
我需要將UltraGrid添加到ultraToolbar中,就像buttontool的常用工具。 我需要顯示自定義表格數據。
我試圖從ToolBase派生userControl,但不知何故它不工作。
我在這裏附上我的代碼。它有一些錯誤。
FilterGrid.cs用戶控件UltraGrid as UltraToolBar

 using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Drawing; 
    using System.Data; 
    using System.Text; 
    using System.Windows.Forms; 
    using Infragistics.Win.UltraWinToolbars; 
    using System.Runtime.Serialization; 
    using Infragistics.Win.UltraWinGrid; 
    using System.Security.Permissions; 
    using Infragistics.Shared.Serialization; 
    using Infragistics.Win.AppStyling; 

    namespace WindowsApplication1 
    { 
     public partial class FilterGrid : UserControl 
     { 
      public FilterGrid() 
      { 
       InitializeComponent(); 
      } 

      [TypeConverter(typeof(FilterGrid.GridInternal))] 
      [Serializable()] 
      private class GridInternal : ToolBase 
      { 

       internal UltraGrid uGrid = new UltraGrid(); 
       #region Constructors 

       public GridInternal(String key) 
        : base(key) 
       { 
        this.SharedProps.Width = 200; 
        this.SharedProps.ToolTipText = "FilterGrid"; 
        this.SharedProps.DisplayStyle = ToolDisplayStyle.DefaultForToolType; 
       } 

       /// <summary> 
       /// Constructor used for de-serialization 
       /// </summary> 
       protected GridInternal(SerializationInfo info, StreamingContext context): base(info, context) 
       { 

       } 

       #endregion 

       #region Constants 

       internal static readonly string DEFAULTVALUE_CUSTOMPROP = "CustomValue"; 

       #endregion Constants 


       #region Base Class Overrides 

       #region GetObjectData 

       /// <summary> 
       /// Called from our base class when ISerializable.GetObjectData is called. Serialize all custom property data here. 
       /// </summary> 
       /// <param name="info"></param> 
       /// <param name="context"></param> 
       [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] 
       protected override void GetObjectData(SerializationInfo info, StreamingContext context) 
       { 
        // Call the base implementation 
        base.GetObjectData(info, context); 


        // Serialize our CustomProp property if necessary. 
        //if (this.ShouldSerializeCustomProp()) 
        // Utils.SerializeProperty(info, "CustomProp", this.CustomProp); 
       } 



       #endregion GetObjectData 



       //#region ISerializable Members 

       //public void GetObjectData(SerializationInfo info, StreamingContext context) 
       //{ 
       // // Call the base implementation 
       // base.GetObjectData(info, context); 


       // // Serialize our CustomProp property if necessary. 
       // if (this.ShouldSerializeCustomProp()) 
       //  Utils.SerializeProperty(info, "CustomProp", this.CustomProp); 
       //} 

       //#endregion 


       #region Initialize 

       /// <summary> 
       /// Internal inherited method for initializing the tool when de-serialization completes. 
       /// Automatically called by toolbars manager. 
       /// </summary> 
       protected override void Initialize(ToolsCollectionBase parentCollection) 
       { 
        // Let the base do its processing. 
        base.Initialize(parentCollection); 


        // Use the temporary member variable to set the actual ExtraSharedProps properties. 
        // We need to wait until after deserialization is totally complete to ensure that 
        // our ExtraSharedProps object is properly setup. 
        //if (this.serializedProps != null) 
        //{ 
        // this.ExtraSharedProps.customProp = this.serializedProps.customProp; 

        // this.serializedProps = null; 
        //} 

       } 

       #endregion Initialize 

       #region Clone 
       /// <summary> 
       /// Returns a cloned copy of the tool. 
       /// </summary> 
       /// <param name="cloneNewInstance">If true, returns a clone of the tool that can serve as an instance of the tool, sharing the same SharedProps object. If false, returns a tool that can be used as a new tool, with a clone of the original SharedProps object.</param> 
       /// <returns></returns> 
       protected override Infragistics.Win.UltraWinToolbars.ToolBase Clone(bool cloneNewInstance) 
       { 
        GridInternal tool = new GridInternal(this.Key); 
        tool.InitializeFrom(this, cloneNewInstance); 
        return tool; 
       } 
       #endregion //Clone 

       #endregion Base Class Overrides 

       #region CustomProp 

       /// <summary> 
       /// This is a custom property in a custom tool. 
       /// </summary> 
       //public string CustomProp 
       //{ 
       // // Delegate the get/sets for the property to our ExtraSharedProps object 

       // get { return this.ExtraSharedProps.CustomProp; } 
       // set { this.ExtraSharedProps.CustomProp = value; } 
       //} 

       /// <summary> 
       /// Returns a Boolean value that determines whether the CustomProp property is set to its default value. 
       /// Checked during serialization to determine if the property should be serialized. 
       /// </summary> 
       internal protected virtual bool ShouldSerializeCustomProp() 
       { 
        // We only want to serialize the property if this tool is the Root tool and the 
        // property is not set to its default value. 
        return (this.IsRootTool); 
       } 

       #endregion CustomProp 

       protected override Type GetToolbarUIElementType() 
       { 
        return typeof(UltraGrid); 
       } 

          AccessibleRole rl = AccessibleRole.Pane; 
       UIRole roleOnMenus ; 
       UIRole roleOnRibbonGroups ; 
       UIRole roleOnToolbars; 

       protected override AccessibleRole DefaultAccessibleRole 
       { 
        get { return this.rl; } 
       } 

       protected override string DefaultAction 
       { 
        get { return "Get"; } 
       } 

       public override Infragistics.Win.AppStyling.UIRole UIRoleOnMenus 
       { 
        get { return this.roleOnMenus; } 
       } 

       public override Infragistics.Win.AppStyling.UIRole UIRoleOnRibbonGroups 
       { 
        get { return this.roleOnRibbonGroups; } 
       } 

       public override Infragistics.Win.AppStyling.UIRole UIRoleOnToolbars 
       { 
        get {return this.roleOnToolbars; } 
       } 
      } 

      private void DrawFilter(UltraToolbarsManager tbm) 
      { 
       GridInternal gdInternal = new GridInternal("gridInternal"); 
       DataTable dt = new DataTable(); 
       dt.Columns.Add("Column1"); 
       dt.Rows.Add(new object[] { "MyRow"}); 
       gdInternal.uGrid.DataSource = dt; 
       gdInternal.SharedProps.Caption = "FilterGrid"; 

       Infragistics.Win.UltraWinToolbars.StateButtonTool stb = new StateButtonTool("isEnabled"); 
       stb.SharedProps.DisplayStyle = ToolDisplayStyle.ImageAndText; 
       stb.SharedProps.CustomizerCaption = "Enable"; 
       stb.SharedProps.Caption = "Enable"; 

       Infragistics.Win.UltraWinToolbars.LabelTool lb = new LabelTool("FilterStatus"); 
       lb.SharedProps.Caption = "FilterStatus"; 

       Infragistics.Win.UltraWinToolbars.StateButtonTool filterstb = new StateButtonTool("Applied"); 
       filterstb.SharedProps.DisplayStyle = ToolDisplayStyle.ImageOnlyOnToolbars; 
       filterstb.SharedProps.CustomizerCaption = "Applied"; 
       filterstb.SharedProps.Caption = "Applied"; 

       Infragistics.Win.UltraWinToolbars.LabelTool lb1 = new LabelTool("SetFilterType"); 
       lb1.SharedProps.Caption = "SetFilterType"; 

       Infragistics.Win.UltraWinToolbars.ComboBoxTool cbTool = new ComboBoxTool("FilterList"); 
       cbTool.SharedProps.Caption = "FilterType"; 
       cbTool.DropDownStyle = Infragistics.Win.DropDownStyle.DropDownList; 
       Infragistics.Win.ValueList vl = new Infragistics.Win.ValueList(); 

       cbTool.ValueList.ValueListItems.Add("Select"); 
       cbTool.ValueList.ValueListItems.Add("List1"); 
       cbTool.ValueList.ValueListItems.Add("List2"); 
       cbTool.ValueList.ValueListItems.Add("List3"); 
       cbTool.ValueList.ValueListItems.Add("List4"); 
       cbTool.SelectedIndex = 0; 
       Infragistics.Win.UltraWinToolbars.ButtonTool btReset = new ButtonTool("Reset"); 
       btReset.SharedProps.DisplayStyle = ToolDisplayStyle.ImageAndText; 
       btReset.SharedProps.Caption = "ResetFilters"; 


       tbm.Tools.AddRange(new ToolBase[] { stb, lb, filterstb, lb1, cbTool, btReset, gdInternal }); 

       UltraToolbar tb = new UltraToolbar("Filter"); 
       tbm.Toolbars.AddToolbar("Filter").Tools.AddToolRange(new String[] { "isEnabled", "FilterStatus", "Applied", "SetFilterType", "FilterList", "Reset", "gridInternal" }); 
       // tb.Tools.AddTool("isEnabled"); 



      } 

      public FilterGrid(UltraToolbarsManager tbm):this() 
      { 
       DrawFilter(tbm); 
      } 



     } 
    } 

Main.cs主要形式

 using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Data; 
    using System.Drawing; 
    using System.Text; 
    using System.Windows.Forms; 

    namespace WindowsApplication1 
    { 
     public partial class Main : Form 
     { 
      public Main() 
      { 
       InitializeComponent(); 
       FilterGrid fg = new FilterGrid(ultraToolbarsManager1); 
      } 
     } 
    } 


編輯
我想在UltraToolbar獲得從Toolbase控制並顯示它,如果可能。

+1

您將需要問一個更簡潔的問題才能收到有用的回覆。 – roken

回答

1

現在我得到了如何做到這一點。
我創建了一個controlContainerTool的實例並將它分配給我的ultragrid。
controlContainerTool也被添加到UltraToolbarsManager和工具欄實例中。
外觀可以在設計時從代碼中設置。

一個最重要的事情是處理網格中的滾動條,如果比預期的大。