DataGridColumnCollection 클래스

정의

DataGridColumn제어의 열을 나타내는 DataGrid 파생 열 개체의 컬렉션입니다. 이 클래스는 상속될 수 없습니다.

public ref class DataGridColumnCollection sealed : System::Collections::ICollection, System::Web::UI::IStateManager
public sealed class DataGridColumnCollection : System.Collections.ICollection, System.Web.UI.IStateManager
type DataGridColumnCollection = class
    interface ICollection
    interface IEnumerable
    interface IStateManager
Public NotInheritable Class DataGridColumnCollection
Implements ICollection, IStateManager
상속
DataGridColumnCollection
구현

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 DataGridColumnCollection 동적으로 열을 추가 하는 컬렉션을 DataGrid 컨트롤. Columns 의 속성을 DataGrid 컨트롤의 인스턴스가 DataGridColumnCollection 클래스입니다.


<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
   <script runat="server">

      ICollection CreateDataSource() 
      {
      
         // Create sample data for the DataGrid control.
         DataTable dt = new DataTable();
         DataRow dr;
 
         // Define the columns of the table.
         dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
         dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
         dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));
 
         // Populate the table with sample values.
         for (int i = 0; i < 9; i++) 
         {
            dr = dt.NewRow();
 
            dr[0] = i;
            dr[1] = "Item " + i.ToString();
            dr[2] = 1.23 * (i + 1);
 
            dt.Rows.Add(dr);
         }
 
         DataView dv = new DataView(dt);
         return dv;

      }
 
      void Page_Load(Object sender, EventArgs e) 
      {

         // Create a DataGrid control.
         DataGrid ItemsGrid = new DataGrid();

         // Set the properties of the DataGrid.
         ItemsGrid.ID = "ItemsGrid";
         ItemsGrid.BorderColor = System.Drawing.Color.Black;
         ItemsGrid.CellPadding = 3;
         ItemsGrid.AutoGenerateColumns = false;

         // Set the styles for the DataGrid.
         ItemsGrid.HeaderStyle.BackColor = 
             System.Drawing.Color.FromArgb(0x0000aaaa);

         // Create the columns for the DataGrid control. The DataGrid
         // columns are dynamically generated. Therefore, the columns   
         // must be re-created each time the page is refreshed.
         
         // Create and add the columns to the collection.
         ItemsGrid.Columns.Add(CreateBoundColumn("IntegerValue", "Item"));
         ItemsGrid.Columns.Add(
             CreateBoundColumn("StringValue", "Description"));
         ItemsGrid.Columns.Add(
             CreateBoundColumn("CurrencyValue", "Price", "{0:c}", 
             HorizontalAlign.Right));
         ItemsGrid.Columns.Add(
             CreateLinkColumn("http://www.microsoft.com", "_self", 
             "Microsoft", "Related link"));
        
         // Specify the data source and bind it to the control.
         ItemsGrid.DataSource = CreateDataSource();
         ItemsGrid.DataBind();

         // Add the DataGrid control to the Controls collection of 
         // the PlaceHolder control.
         Place.Controls.Add(ItemsGrid);

      }

      BoundColumn CreateBoundColumn(String DataFieldValue, 
          String HeaderTextValue)
      {

         // This version of the CreateBoundColumn method sets only the
         // DataField and HeaderText properties.

         // Create a BoundColumn.
         BoundColumn column = new BoundColumn();

         // Set the properties of the BoundColumn.
         column.DataField = DataFieldValue;
         column.HeaderText = HeaderTextValue;

         return column;

      }

      BoundColumn CreateBoundColumn(String DataFieldValue, 
          String HeaderTextValue, String FormatValue, 
          HorizontalAlign AlignValue)
      {

         // This version of CreateBoundColumn method sets the DataField,
         // HeaderText, and DataFormatString properties. It also sets the 
         // HorizontalAlign property of the ItemStyle property of the column. 

         // Create a BoundColumn using the overloaded CreateBoundColumn method.
         BoundColumn column = CreateBoundColumn(DataFieldValue, HeaderTextValue);

         // Set the properties of the BoundColumn.
         column.DataFormatString = FormatValue;
         column.ItemStyle.HorizontalAlign = AlignValue;

         return column;

      }

      HyperLinkColumn CreateLinkColumn(String NavUrlValue, 
          String TargetValue, String TextValue, String HeaderTextValue)
      {

         // Create a BoundColumn.
         HyperLinkColumn column = new HyperLinkColumn();

         // Set the properties of the ButtonColumn.
         column.NavigateUrl = NavUrlValue;
         column.Target = TargetValue;
         column.Text = TextValue;
         column.HeaderText = HeaderTextValue;

         return column;

      }

   </script>
 
<head runat="server">
    <title>DataGrid Constructor Example</title>
</head>
<body>
 
   <form id="form1" runat="server">
 
      <h3>DataGrid Constructor Example</h3>
 
      <b>Product List</b>

      <asp:PlaceHolder id="Place"
           runat="server"/>
 
   </form>
 
</body>
</html>

<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
   <script runat="server">

      Function CreateDataSource() As ICollection 
      
         ' Create sample data for the DataGrid control.
         Dim dt As DataTable = New DataTable()
         Dim dr As DataRow
 
         ' Define the columns of the table.
         dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
         dt.Columns.Add(New DataColumn("StringValue", GetType(string)))
         dt.Columns.Add(New DataColumn("CurrencyValue", GetType(double)))
 
         ' Populate the table with sample values.
         Dim i As Integer

         For i = 0 to 8 
        
            dr = dt.NewRow()
 
            dr(0) = i
            dr(1) = "Item " & i.ToString()
            dr(2) = 1.23 * (i + 1)
 
            dt.Rows.Add(dr)

         Next i
 
         Dim dv As DataView = New DataView(dt)
         Return dv

      End Function
 
      Sub Page_Load(sender As Object, e As EventArgs) 

         ' Create a DataGrid control.
         Dim ItemsGrid As DataGrid = New DataGrid()

         ' Set the properties of the DataGrid.
         ItemsGrid.ID = "ItemsGrid"
         ItemsGrid.BorderColor = System.Drawing.Color.Black
         ItemsGrid.CellPadding = 3
         ItemsGrid.AutoGenerateColumns = False

         ' Set the styles for the DataGrid.
         ItemsGrid.HeaderStyle.BackColor = System.Drawing.Color.FromArgb(&H0000aaaa)

         ' Create the columns for the DataGrid control. The DataGrid
         ' columns are dynamically generated. Therefore, the columns   
         ' must be re-created each time the page is refreshed.
         
         ' Create and add the columns to the collection.
         ItemsGrid.Columns.Add(CreateBoundColumn("IntegerValue", "Item"))
         ItemsGrid.Columns.Add( _
             CreateBoundColumn("StringValue", "Description"))
         ItemsGrid.Columns.Add( _
             CreateBoundColumn("CurrencyValue", "Price", "{0:c}", _
             HorizontalAlign.Right))
         ItemsGrid.Columns.Add( _
             CreateLinkColumn("http:'www.microsoft.com", "_self", _
             "Microsoft", "Related link"))
        
         ' Specify the data source and bind it to the control.     
         ItemsGrid.DataSource = CreateDataSource()
         ItemsGrid.DataBind()

         ' Add the DataGrid control to the Controls collection of 
         ' the PlaceHolder control.
         Place.Controls.Add(ItemsGrid)

      End Sub

      Function CreateBoundColumn(DataFieldValue As String, HeaderTextValue As String) As BoundColumn

         ' This version of CreateBoundColumn method sets only the 
         ' DataField and HeaderText properties.

         ' Create a BoundColumn.
         Dim column As BoundColumn = New BoundColumn()

         ' Set the properties of the BoundColumn.
         column.DataField = DataFieldValue
         column.HeaderText = HeaderTextValue

         Return column

      End Function

      Function CreateBoundColumn(DataFieldValue As String, _
          HeaderTextValue As String, FormatValue As String, _
          AlignValue As HorizontalAlign) As BoundColumn

         ' This version of CreateBoundColumn method sets the DataField,
         ' HeaderText, and DataFormatString properties. It also sets the 
         ' HorizontalAlign property of the ItemStyle property of the column. 

         ' Create a BoundColumn using the overloaded CreateBoundColumn method.
         Dim column As BoundColumn = CreateBoundColumn(DataFieldValue, HeaderTextValue)

         ' Set the properties of the BoundColumn.
         column.DataFormatString = FormatValue
         column.ItemStyle.HorizontalAlign = AlignValue

         Return column

      End Function

      Function CreateLinkColumn(NavUrlValue As String, TargetValue As String, _
         TextValue As String, HeaderTextValue As String) As HyperLinkColumn 

         ' Create a BoundColumn.
         Dim column As HyperLinkColumn = New HyperLinkColumn()

         ' Set the properties of the ButtonColumn.
         column.NavigateUrl = NavUrlValue
         column.Target = TargetValue
         column.Text = TextValue
         column.HeaderText = HeaderTextValue

         Return column

      End Function

   </script>
 
<head runat="server">
    <title>DataGrid Constructor Example</title>
</head>
<body>
 
   <form id="form1" runat="server">
 
      <h3>DataGrid Constructor Example</h3>
 
      <b>Product List</b>

      <asp:PlaceHolder id="Place"
           runat="server"/>
 
   </form>
 
</body>
</html>

설명

사용 된 DataGridColumnCollection 프로그래밍 방식으로 컬렉션을 관리 하는 컬렉션 DataGridColumn-파생 열 개체입니다. 이러한 개체의 열을 나타냅니다는 DataGrid 제어 합니다. 추가, 제거 또는 열에 삽입 된 DataGridColumnCollection 컬렉션입니다.

참고

경우는 AutoGenerateColumns 속성이로 설정 된 true, 에서 만든 열을 DataGrid 컨트롤에 추가 되지 않습니다는 Columns 컬렉션.

합니다 DataGrid 컨트롤의 내용을 저장 하지 않습니다 해당 Columns 보기 상태의 컬렉션. 를 추가 하거나 열을 동적으로 제거 하려면 하면 프로그래밍 방식으로 추가 하거나 제거 해야 열 페이지를 새로 고칠 때마다 합니다. 제공을 Page_Init 함수를 추가 하거나 제거 하기 전에 열을 DataGrid 컨트롤의 상태를 다시 로드 하 고 컨트롤은 다시 작성 합니다. 이 고, 그렇지 변경 합니다 Columns 컬렉션에 반영 되지 않습니다는 DataGrid 표시 되 면 제어 합니다.

참고

프로그래밍 방식으로 열을 추가 하거나 열을 제거할 수 있지만 Columns 의 컬렉션을 DataGrid 제어 하기가 정적 열을 나열 하 고 사용 하 여는 Visible 각 열을 표시 하거나 숨기려면 속성입니다.

열에 표시 되는 순서를 결정 하는 컬렉션의 열 순서는 DataGrid 제어 합니다.

다음 표에서 다른 열에서 파생 된 클래스는 DataGridColumn 클래스입니다.

열 클래스 Description
BoundColumn 데이터 원본의 필드에에서 바인딩되는 열입니다. 필드의 각 항목 텍스트로 표시합니다. 이 기본 형식인 열에 대 한는 DataGrid 제어 합니다.
ButtonColumn 열에서 각 항목에 대 한 명령 단추를 표시 하는 열입니다. 이 단추를 추가 또는 제거와 같은 사용자 지정 단추 컨트롤의 열을 만들 수 있습니다.
EditCommandColumn 열에서 각 항목에 대 한 편집 명령을 포함 하는 열입니다.
HyperLinkColumn 하이퍼링크 열에 각 항목을 표시 하는 열입니다. 열 내용의 정적 텍스트 또는 데이터 원본의 필드에 바인딩할 수 있습니다.
TemplateColumn 지정된 된 서식 파일에 따라 열에 각 항목을 표시 하는 열입니다. 이 옵션을 사용 하면 예를 들어 이미지를 표시 하는 열의 내용을 제어할 수 있습니다.

참고

DataGridColumn 클래스는 나열 된 열 클래스에 대 한 기본 클래스입니다. 직접 사용 되지 않습니다는 DataGridColumnCollection 컬렉션입니다.

생성자

DataGridColumnCollection(DataGrid, ArrayList)

DataGridColumnCollection 클래스의 새 인스턴스를 초기화합니다.

속성

Count

DataGridColumnCollection 컬렉션에 있는 열의 수를 가져옵니다.

IsReadOnly

DataGridColumnCollection 컬렉션에 있는 열을 수정할 수 있는지 여부를 나타내는 값을 가져옵니다.

IsSynchronized

DataGridColumnCollection 컬렉션에 대한 액세스가 동기화되는지 즉, 스레드로부터 안전하게 보호되는지 여부를 나타내는 값을 가져옵니다.

Item[Int32]

DataGridColumn 컬렉션에서 지정된 인덱스에 해당하는 DataGridColumnCollection 파생 열 개체를 가져옵니다.

SyncRoot

DataGridColumnCollection 컬렉션에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

메서드

Add(DataGridColumn)

지정된 DataGridColumn 파생 열 개체를 DataGridColumnCollection 컬렉션의 끝에 추가합니다.

AddAt(Int32, DataGridColumn)

DataGridColumn 파생 열 개체를 지정된 인덱스에 해당하는 DataGridColumnCollection 컬렉션에 삽입합니다.

Clear()

DataGridColumn 컬렉션에서 DataGridColumnCollection 파생 열 개체를 모두 제거합니다.

CopyTo(Array, Int32)

DataGridColumnCollection의 지정된 인덱스에서 시작하여 Array 컬렉션에서 지정된 Array로 항목을 복사합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetEnumerator()

IEnumerator 컬렉션에 있는 모든 DataGridColumn 파생 열 개체가 들어 있는 DataGridColumnCollection 인터페이스를 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IndexOf(DataGridColumn)

DataGridColumn 컬렉션에서 지정된 DataGridColumnCollection 파생 열 개체의 인덱스를 반환합니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Remove(DataGridColumn)

DataGridColumn 컬렉션에서 지정된 DataGridColumnCollection 파생 열 개체를 제거합니다.

RemoveAt(Int32)

DataGridColumn 컬렉션에서 지정된 인덱스에 해당하는 DataGridColumnCollection 파생 열 개체를 제거합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

IStateManager.IsTrackingViewState

컬렉션에서 뷰 상태 변경 내용을 추적하는지 여부를 나타내는 값을 가져옵니다.

IStateManager.LoadViewState(Object)

이전에 저장된 상태를 로드합니다.

IStateManager.SaveViewState()

상태 변경 사항이 포함된 개체를 반환합니다.

IStateManager.TrackViewState()

상태 변경 사항 추적을 시작합니다.

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상

추가 정보