我需要的是一个非常定制的情况。
我需要将 UltraGrid 添加到 ultraToolbar 作为普通工具,如 buttontool。我需要在哪里显示自定义表格数据。
我试图从 ToolBase 派生一个 userControl 但不知何故它不起作用。
我在这里附上我的代码。它有一些错误。
FilterGrid.cs用户控件
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);
}
}
}
编辑
如果可能的话,我想从 Toolbase 派生一个控件并将其显示在 UltraToolbar 上。