次の方法で共有


DataGridDesigner クラス

DataGrid Web サーバー コントロールのデザイン時の動作を拡張します。

この型のすべてのメンバの一覧については、DataGridDesigner メンバ を参照してください。

System.Object
   System.ComponentModel.Design.ComponentDesigner
      System.Web.UI.Design.HtmlControlDesigner
         System.Web.UI.Design.ControlDesigner
            System.Web.UI.Design.TemplatedControlDesigner
               System.Web.UI.Design.WebControls.BaseDataListDesigner
                  System.Web.UI.Design.WebControls.DataGridDesigner

Public Class DataGridDesigner
   Inherits BaseDataListDesigner
[C#]
public class DataGridDesigner : BaseDataListDesigner
[C++]
public __gc class DataGridDesigner : public BaseDataListDesigner
[JScript]
public class DataGridDesigner extends BaseDataListDesigner

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

使用例

[Visual Basic] SimpleDataGridDesigner という名前のクラスを DataGridDesigner クラスから継承して作成するコード例を次に示します。このクラスは、 System.Web.UI.WebControls.DataGrid の派生クラスである SimpleDataGrid クラスと組み合わせて使用します。このデザイナ クラスは GetDesignTimeHtml メソッドをオーバーライドして、 SimpleDataGrid クラスが Visual Studio .NET などのデザイン画面上で表示を実行するときの CellPaddingBorderWidth 、および BorderColor プロパティをカスタマイズします。

 
' Create a class that derives from DataGridDesigner
' that displays the custom SimpleDataGrid control
' on a design surface.
Imports System
Imports System.Design
Imports System.Drawing
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design.WebControls
Imports Examples.AspNet

Namespace Examples.AspNet.Design

<System.Security.Permissions.SecurityPermission( _
    System.Security.Permissions.SecurityAction.Demand, _
    Flags:=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)> _
Public Class SimpleDataGridDesigner
   Inherits DataGridDesigner
   
   Private simpleGrid As SimpleDataGrid 

   ' Override the GetDesignTimeHtml method.
   Public Overrides Function GetDesignTimeHtml() As String

      Dim designTimeHtml As String = Nothing      
      
      ' Check the control's BorderStyle property
      ' to conditionally render design-time HTML.
      If (simpleGrid.BorderStyle = BorderStyle.NotSet) Then

          ' Create variables to hold current property settings.
          Dim oldCellPadding As Integer = simpleGrid.CellPadding
          Dim oldBorderWidth As Unit = simpleGrid.BorderWidth
          Dim oldBorderColor As Color = simpleGrid.BorderColor
          
          ' Set properties and the design-time HTML.
          Try
              simpleGrid.CellPadding = 1
              simpleGrid.BorderWidth = Unit.Pixel(3)
              simpleGrid.BorderColor = Color.Brown
              designTimeHtml = MyBase.GetDesignTimeHtml()
                
          ' If an exception occurs, call the GetErrorDesignTimeHtml
          ' method.
          Catch ex As Exception
              designTimeHtml = GetErrorDesignTimeHtml(ex)

          ' Return properties to their original settings.
          Finally
              simpleGrid.CellPadding = oldCellPadding
              simpleGrid.BorderWidth = oldBorderWidth
              simpleGrid.BorderColor = oldBorderColor
          End Try
          
      Else
          designTimeHtml = MyBase.GetDesignTimeHtml()
      End If
      
      Return designTimeHTML

   End Function 

   ' Write a string to the design surface if an error
   ' occurs while trying to render to the designer.
   Protected Overrides Function GetErrorDesignTimeHtml(exc As Exception) As String
      
      Debug.Fail(exc.ToString())
      
      Return CreatePlaceHolderDesignTimeHtml( _
       "An error occurred while rendering to the designer.")

   End Function


   ' Override the Initialize method to ensure that
   ' only an instance of the SimpleDataGrid class is 
   ' used by this designer class.
   Public Overrides Sub Initialize(component As IComponent)
      Debug.Assert( _
        TypeOf component Is SimpleDataGrid, _
        "SimpleDataGridDesigner::Initialize - Invalid SimpleDataGrid Control")
      
      simpleGrid = CType(component, SimpleDataGrid)

      MyBase.Initialize(component)
   End Sub
   
  End Class 
End Namespace

[Visual Basic] System.ComponentModel.DesignerAttribute クラスを使用して、 SimpleDataGridDesigner クラスを SimpleDataGrid クラスに関連付けるコード例を次に示します。

 
Imports System
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.Web.UI.Design.WebControls
Imports System.Windows.Forms.Design

Namespace Examples.AspNet
    
    ' Associate the SimpleDataGrid class with
    ' its designer with the DesignerAttribute class.
    ' Use the EditorAttribute class to associate
    ' SimpleDataGrid with the DataGridComponentEditor
    ' class.
    <DesignerAttribute( _
        GetType(Examples.AspNet.Design.SimpleDataGridDesigner)), _
     EditorAttribute(GetType(DataGridComponentEditor), _
         GetType(ComponentEditor)) _
    > _
    Public Class SimpleDataGrid
        Inherits DataGrid
        
        ' Include code here for a customized
        ' DataGrid class.
        
    End Class
End Namespace

[C#, C++, JScript] C#、C++、および JScript のサンプルはありません。Visual Basic のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Web.UI.Design.WebControls

プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Design (System.Design.dll 内)

参照

DataGridDesigner メンバ | System.Web.UI.Design.WebControls 名前空間 | DataGrid | DataGridComponentEditor