GridViewDesigner クラス
アセンブリ: System.Design (system.design.dll 内)


ビジュアルなデザイナでソース ビューからデザイン ビューに切り替えると、GridView コントロールを記述するマークアップのソース コードが解析され、コントロールのデザイン時バージョンがデザイン サーフェイスに作成されます。元のソース ビューに切り替えると、デザイン時コントロールがマークアップのソース コードに永続化され、Web ページのマークアップに反映されます。
GridViewDesigner クラスのプロパティは、次の機能を提供します。
-
ActionLists プロパティは、DesignerActionListCollection オブジェクトを返します。一般にこのオブジェクトには、デザイナの継承ツリーの各レベルについて、DesignerActionList クラスから派生したオブジェクトが格納されます。
-
AutoFormats プロパティは、[オートフォーマット] ダイアログ ボックスで表示するための書式指定スキームのコレクションを返します。
-
TemplateGroups プロパティは、関連付けられた GridView コントロールとトップレベルの GridView テンプレートについて、テンプレート グループのコレクションを返します。
-
UsePreviewControl プロパティは、常に true を返します。デザイナは、関連付けられた GridView の一時的なコピーを作成して、デザイン時のマークアップを生成します。
GridViewDesigner クラスのメソッドは、次の機能を提供します。
-
GetDesignTimeHtml メソッドは、デザイン時に、関連付けられた GridView のレンダリングに使用するマークアップを返します。
-
Initialize メソッドは、関連付けられた GridView をデザイナで表示、編集、デザインできるように準備します。
-
OnClick メソッドは、関連付けられた GridView のデザイン時ビューの領域がクリックされたときに呼び出されます。
-
OnSchemaRefreshed メソッドは、関連付けられた GridView のデータ ソースのスキーマが変更されたときに呼び出されます。
-
PreFilterProperties メソッドは、関連付けられた GridView に対して、プロパティの削除、追加、シャドウを行う場合に使用します。
GridView コントロールでは、デザイン時の編集可能領域がサポートされていないため、GetEditableDesignerRegionContent メソッドと SetEditableDesignerRegionContent メソッドは何の機能も提供しません。

GridViewDesigner クラスを拡張し、GridView コントロールから派生したコントロールの外観をデザイン時に変更するコード例を次に示します。
この例では、MyGridView コントロールを GridView から派生させています。MyGridView は、単に GridView のコピーです。また、この例では、GridViewDesigner クラスから MyGridViewDesigner クラスを派生して、MyGridViewDesigner の DesignerAttribute オブジェクトを MyGridView コントロールに配置します。
MyGridViewDesigner は、PreFilterProperties メソッドをオーバーライドし、デザイン時に、[プロパティ] グリッドに Page プロパティを表示します。さらに、GetDesignTimeHtml メソッドをオーバーライドして、Caption プロパティが指定されている場合は、デザイン時に、MyGridView コントロールの新しい先頭行としてこのプロパティを挿入します。MyGridView コントロールの BorderStyle プロパティの値が NotSet または None の場合、GetDesignTimeHtml は、コントロールの周囲に青い点線の境界線を描画して、コントロールの範囲をわかりやすくします。
Imports System Imports System.Web Imports System.Drawing Imports System.Web.UI.WebControls Imports System.Web.UI.Design.WebControls Imports System.Collections Imports System.ComponentModel Imports System.Security.Permissions Namespace Examples.VB.WebControls.Design ' The MyGridView is a copy of the GridView. <AspNetHostingPermission(SecurityAction.Demand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermission(SecurityAction.InheritanceDemand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ <Designer(GetType(Examples.VB.WebControls.Design.MyGridViewDesigner))> _ Public Class MyGridView Inherits GridView End Class ' MyVBGridView ' Override members of the GridViewDesigner. <ReflectionPermission(SecurityAction.Demand, Flags:=ReflectionPermissionFlag.MemberAccess)> _ Public Class MyGridViewDesigner Inherits GridViewDesigner ' Shadow the control properties with design-time properties. Protected Overrides Sub PreFilterProperties( _ ByVal properties As IDictionary) ' Call the base method first. MyBase.PreFilterProperties(properties) ' Make the Page visible in the Properties grid. Dim selectProp As PropertyDescriptor = _ CType(properties("Page"), PropertyDescriptor) properties("Page") = _ TypeDescriptor.CreateProperty(selectProp.ComponentType, _ selectProp, BrowsableAttribute.Yes) End Sub ' PreFilterProperties ' Generate the design-time markup. Private Const capTag As String = "caption" Private Const trOpen As String = "tr><td colspan=9 align=center" Private Const trClose As String = "td></tr" Public Overrides Function GetDesignTimeHtml() As String ' Make the full extent of the control more visible in the designer. ' If the border style is None or NotSet, change the border to ' a wide, blue, dashed line. Include the caption within the border. Dim myGV As MyGridView = CType(Component, MyGridView) Dim markup As String = Nothing Dim charX As Integer ' Check if the border style should be changed. If (myGV.BorderStyle = BorderStyle.NotSet Or _ myGV.BorderStyle = BorderStyle.None) Then Dim oldBorderStyle As BorderStyle = myGV.BorderStyle Dim oldBorderWidth As Unit = myGV.BorderWidth Dim oldBorderColor As Color = myGV.BorderColor ' Set the design-time properties and catch any exceptions. Try myGV.BorderStyle = BorderStyle.Dashed myGV.BorderWidth = Unit.Pixel(3) myGV.BorderColor = Color.Blue ' Call the base method to generate the markup. markup = MyBase.GetDesignTimeHtml() Catch ex As Exception markup = GetErrorDesignTimeHtml(ex) Finally ' Restore the properties to their original settings. myGV.BorderStyle = oldBorderStyle myGV.BorderWidth = oldBorderWidth myGV.BorderColor = oldBorderColor End Try Else ' Call the base method to generate the markup. markup = MyBase.GetDesignTimeHtml() End If ' Look for a <caption> tag. charX = markup.IndexOf(capTag) If charX > 0 Then ' Replace the first caption with ' "tr><td colspan=9 align=center". ' It is okay if the colspan exceeds the ' number of columns in the table. markup = markup.Remove(charX, _ capTag.Length).Insert(charX, trOpen) ' Replace the second caption with "td></tr". charX = markup.IndexOf(capTag, charX) If charX > 0 Then markup = markup.Remove(charX, _ capTag.Length).Insert(charX, trClose) End If End If Return markup End Function ' GetDesignTimeHtml End Class ' MyGridViewDesigner End Namespace ' Examples.VB.WebControls.Design
using System; using System.Web; using System.Drawing; using System.Web.UI.WebControls; using System.Web.UI.Design.WebControls; using System.Collections; using System.ComponentModel; using System.Security.Permissions; namespace Examples.CS.WebControls.Design { // The MyGridView is a copy of the GridView. [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] [Designer(typeof(Examples.CS.WebControls.Design.MyGridViewDesigner))] public class MyGridView : GridView { } // MyGridView // Override members of the GridViewDesigner. [ReflectionPermission(SecurityAction.Demand, Flags=ReflectionPermissionFlag.MemberAccess)] public class MyGridViewDesigner : GridViewDesigner { // Shadow the control properties with design-time properties. protected override void PreFilterProperties(IDictionary properties) { // Call the base method first. base.PreFilterProperties(properties); // Make the Page visible in the Properties grid. PropertyDescriptor selectProp = (PropertyDescriptor)properties["Page"]; properties["Page"] = TypeDescriptor.CreateProperty(selectProp.ComponentType, selectProp, BrowsableAttribute.Yes); } // PreFilterProperties // Generate the design-time markup. const string capTag = "caption"; const string trOpen = "tr><td colspan=9 align=center"; const string trClose = "td></tr"; public override string GetDesignTimeHtml() { // Make the full extent of the control more visible in the designer. // If the border style is None or NotSet, change the border to // a wide, blue, dashed line. Include the caption within the border. MyGridView myGV = (MyGridView)Component; string markup = null; int charX; // Check if the border style should be changed. if (myGV.BorderStyle == BorderStyle.NotSet || myGV.BorderStyle == BorderStyle.None) { BorderStyle oldBorderStyle = myGV.BorderStyle; Unit oldBorderWidth = myGV.BorderWidth; Color oldBorderColor = myGV.BorderColor; // Set the design-time properties and catch any exceptions. try { myGV.BorderStyle = BorderStyle.Dashed; myGV.BorderWidth = Unit.Pixel(3); myGV.BorderColor = Color.Blue; // Call the base method to generate the markup. markup = base.GetDesignTimeHtml(); } catch (Exception ex) { markup = GetErrorDesignTimeHtml(ex); } finally { // Restore the properties to their original settings. myGV.BorderStyle = oldBorderStyle; myGV.BorderWidth = oldBorderWidth; myGV.BorderColor = oldBorderColor; } } else // Call the base method to generate the markup. markup = base.GetDesignTimeHtml(); // Look for a <caption> tag. if ((charX = markup.IndexOf(capTag)) > 0) { // Replace the first caption with // "tr><td colspan=9 align=center". // It is okay if the colspan exceeds the // number of columns in the table. markup = markup.Remove(charX, capTag.Length).Insert(charX, trOpen); // Replace the second caption with "td></tr". if ((charX = markup.IndexOf(capTag, charX)) > 0) markup = markup.Remove(charX, capTag.Length).Insert(charX, trClose); } return markup; } // GetDesignTimeHtml } // MyGridViewDesigner } // Examples.CS.WebControls.Design

System.ComponentModel.Design.ComponentDesigner
System.Web.UI.Design.HtmlControlDesigner
System.Web.UI.Design.ControlDesigner
System.Web.UI.Design.WebControls.BaseDataBoundControlDesigner
System.Web.UI.Design.WebControls.DataBoundControlDesigner
System.Web.UI.Design.WebControls.GridViewDesigner


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- GridViewDesigner クラスのページへのリンク