DataRow.Item[] 속성

정의

지정된 열에 저장된 데이터를 가져오거나 설정합니다.

오버로드

Item[DataColumn]

지정된 DataColumn에 저장된 데이터를 가져오거나 설정합니다.

Item[Int32]

지정된 인덱스를 가진 열에 저장된 데이터를 가져오거나 설정합니다.

Item[String]

지정된 이름을 가진 열에 저장된 데이터를 가져오거나 설정합니다.

Item[DataColumn, DataRowVersion]

지정된 DataColumn에 저장된 특정 버전의 데이터를 가져옵니다.

Item[Int32, DataRowVersion]

검색할 데이터의 지정된 버전 및 인덱스를 가진 열에 저장된 데이터를 가져옵니다.

Item[String, DataRowVersion]

명명된 열에 저장된 특정 버전의 데이터를 가져옵니다.

Item[DataColumn]

Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs

지정된 DataColumn에 저장된 데이터를 가져오거나 설정합니다.

public:
 property System::Object ^ default[System::Data::DataColumn ^] { System::Object ^ get(System::Data::DataColumn ^ column); void set(System::Data::DataColumn ^ column, System::Object ^ value); };
public object this[System.Data.DataColumn column] { get; set; }
member this.Item(System.Data.DataColumn) : obj with get, set
Default Public Property Item(column As DataColumn) As Object

매개 변수

column
DataColumn

데이터가 들어 있는 DataColumn입니다.

속성 값

데이터가 포함된 Object입니다.

예외

열이 이 테이블에 속하지 않는 경우

column가 null인 경우

삭제된 행에 값을 설정하려고 한 경우

값과 열의 데이터 형식이 일치하지 않는 경우

예제

다음 예제에서는 사용 하는 방법을 보여 Item[] 줍니다는 특정 열 인덱스의 값을 가져오고 설정 하는 속성입니다. 첫 번째 예제에서는 사용자가 컨트롤에서 클릭 DataGrid 하는 행의 첫 번째 열 값을 가져옵니다. 두 번째는 메서드에 인수로 전달된 값을 설정합니다.

Private Sub DataGrid1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs)
    
    Dim dataGridTable As DataTable = _
        CType(DataGrid1.DataSource, DataTable)
    ' Set the current row using the RowNumber 
    ' property of the CurrentCell.
    Dim currentRow As DataRow = _
        dataGridTable.Rows(DataGrid1.CurrentCell.RowNumber)
    Dim column As DataColumn = dataGridTable.Columns(1)

    ' Get the value of the column 1 in the DataTable.
    label1.Text = currentRow(column).ToString()
End Sub
 
Private Sub SetDataRowValue( _
    ByVal grid As DataGrid, ByVal newVal As Object)

    ' Set the value of a column in the last row of a DataGrid.
    Dim table As DataTable = CType(grid.DataSource, DataTable)
    Dim row As DataRow = table.Rows(table.Rows.Count - 1)
    Dim column As DataColumn = table.Columns("FirstName")
    row(column)= newVal
End Sub

설명

속성을 설정하면 이벤트에서 예외가 발생하면 예외가 ColumnChanging 생성됩니다.

즉각적인 편집인 경우 생성할 수 있는 예외를 참조 EndEdit 하세요.

적용 대상

Item[Int32]

Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs

지정된 인덱스를 가진 열에 저장된 데이터를 가져오거나 설정합니다.

public:
 property System::Object ^ default[int] { System::Object ^ get(int columnIndex); void set(int columnIndex, System::Object ^ value); };
public object this[int columnIndex] { get; set; }
member this.Item(int) : obj with get, set
Default Public Property Item(columnIndex As Integer) As Object

매개 변수

columnIndex
Int32

열의 인덱스(0부터 시작)입니다.

속성 값

데이터가 포함된 Object입니다.

예외

삭제된 행에 값을 설정하려고 하는 경우

columnIndex 인수가 범위를 벗어난 경우

값과 새 값의 Type 설정이 DataType과 일치하지 않는 경우

예제

다음 예제에서는 사용 하는 방법을 보여 Item[] 줍니다는 특정 열 인덱스의 값을 가져오고 설정 하는 속성입니다. 첫 번째 예제에서는 사용자가 컨트롤에서 클릭 DataGrid 하는 행의 첫 번째 열 값을 가져옵니다.

private void DataGrid1_Click(object sender,
    System.EventArgs e)
{
    // Get the DataTable the grid is bound to.
    DataGrid thisGrid = (DataGrid) sender;
    DataTable table = (DataTable) thisGrid.DataSource;
    DataRow currentRow =
        table.Rows[thisGrid.CurrentCell.RowNumber];

    // Get the value of the column 1 in the DataTable.
    Console.WriteLine(currentRow[1]);
    // You can also use the name of the column:
    // Console.WriteLine(currentRow["FirstName"])
}

private void SetDataRowValue(DataGrid grid, object newValue)
{
    // Set the value of the last column in the last row of a DataGrid.
    DataTable table;
    table = (DataTable) grid.DataSource;
    DataRow row;

    // Get last row
    row = (DataRow)table.Rows[table.Rows.Count-1];

    // Set value of last column
    row[table.Columns.Count-1] = newValue;
}
Private Sub DataGrid1_Click _
    (ByVal sender As System.Object, ByVal e As System.EventArgs)

    ' Get the DataTable the grid is bound to.
    Dim thisGrid As DataGrid = CType(sender, DataGrid)
    Dim table As DataTable = CType(thisGrid.DataSource, DataTable)
    Dim currentRow As DataRow = _
        table.Rows(thisGrid.CurrentCell.RowNumber)

    ' Get the value of the column 1 in the DataTable.
    Console.WriteLine(currentRow(1))
    ' You can also use the name of the column:
    ' Console.WriteLine(currentRow("FirstName"))
    End Sub

    Private Sub SetDataRowValue( _
        ByVal grid As DataGrid, ByVal newValue As Object)

    ' Set the value of the last column in the last row of a DataGrid.
    Dim table As DataTable
    table = CType(grid.DataSource, DataTable)
    Dim row As DataRow 
    row = table.Rows(table.Rows.Count-1)
    row(table.Columns.Count-1) = newValue
End Sub

설명

속성을 설정하면 이벤트에서 예외가 발생하면 예외가 ColumnChanging 생성됩니다.

편집인 경우 생성할 수 있는 예외를 참조 EndEdit 하세요.

적용 대상

Item[String]

Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs

지정된 이름을 가진 열에 저장된 데이터를 가져오거나 설정합니다.

public:
 property System::Object ^ default[System::String ^] { System::Object ^ get(System::String ^ columnName); void set(System::String ^ columnName, System::Object ^ value); };
public object this[string columnName] { get; set; }
member this.Item(string) : obj with get, set
Default Public Property Item(columnName As String) As Object

매개 변수

columnName
String

열 이름입니다.

속성 값

데이터가 포함된 Object입니다.

예외

columnName에서 지정한 열을 찾을 수 없는 경우

삭제된 행에 값을 설정하려고 하는 경우

설정한 값에 대해 해당 TypeDataType과 일치하지 않는 경우

AllowDBNullfalse로 설정된 열에 null 값을 삽입하려고 할 때 발생합니다.

예제

다음 예제에서는 사용 하는 방법을 보여 Item[] 줍니다는 특정 열 인덱스의 값을 가져오고 설정 하는 속성입니다. 첫 번째 예제에서는 사용자가 컨트롤에서 클릭 DataGrid 하는 행의 첫 번째 열 값을 가져옵니다. 두 번째는 메서드에 인수로 전달된 값을 설정합니다.

private void DataGrid1_Click(
    object sender, System.EventArgs e)
{
    // Get the DataTable the grid is bound to.
    DataGrid thisGrid = (DataGrid) sender;
    DataTable table = (DataTable) thisGrid.DataSource;
    DataRow currentRow =
        table.Rows[thisGrid.CurrentCell.RowNumber];

    // Get the value of the column 1 in the DataTable.
    Console.WriteLine(currentRow["FirstName"]);
    // You can also use the index:
    // Console.WriteLine(currentRow[1]);
}

private void SetDataRowValue(
    DataGrid grid, object newValue)
{
    // Set the value of the first column in
    // the last row of a DataGrid.
    DataTable table = (DataTable) grid.DataSource;
    DataRow row = table.Rows[table.Rows.Count-1];
    row["FirstName"] = newValue;
}
Private Sub DataGrid1_Click( _
    sender As Object, e As System.EventArgs)
     
    ' Get the DataTable the grid is bound to.
    Dim thisGrid As DataGrid = CType(sender, DataGrid)
    Dim table As DataTable = _
        CType(thisGrid.DataSource, DataTable)
    Dim currentRow As DataRow = _
        table.Rows(thisGrid.CurrentCell.RowNumber)

    ' Get the value of the column 1 in the DataTable.
    Console.WriteLine(currentRow("FirstName"))
    ' You can also use the index:
    ' Console.WriteLine(currentRow(1).ToString())
End Sub
    
Private Sub SetDataRowValue( _
    grid As DataGrid, newValue As Object)
    ' Set the value of the first column in 
    ' the last row of a DataGrid.
    Dim table As DataTable = _
        CType(grid.DataSource, DataTable)
    Dim row As DataRow
    row = table.Rows((table.Rows.Count - 1))
    row("FirstName") = newValue
End Sub

설명

속성을 설정하면 이벤트에서 예외가 발생하면 예외가 ColumnChanging 생성됩니다.

즉각적인 편집인 경우 생성할 수 있는 예외를 참조 EndEdit 하세요.

적용 대상

Item[DataColumn, DataRowVersion]

Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs

지정된 DataColumn에 저장된 특정 버전의 데이터를 가져옵니다.

public:
 property System::Object ^ default[System::Data::DataColumn ^, System::Data::DataRowVersion] { System::Object ^ get(System::Data::DataColumn ^ column, System::Data::DataRowVersion version); };
public object this[System.Data.DataColumn column, System.Data.DataRowVersion version] { get; }
member this.Item(System.Data.DataColumn * System.Data.DataRowVersion) : obj
Default Public ReadOnly Property Item(column As DataColumn, version As DataRowVersion) As Object

매개 변수

column
DataColumn

열에 대한 정보가 들어 있는 DataColumn입니다.

version
DataRowVersion

원하는 행 버전을 지정하는 DataRowVersion 값 중 하나입니다. 가능한 값은 Default, Original, CurrentProposed입니다.

속성 값

데이터가 포함된 Object입니다.

예외

열이 테이블에 속하지 않는 경우

column 인수에 null이 포함된 경우

행에 이 버전의 데이터가 없는 경우

예제

다음 예제에서는 컨트롤에서 클릭한 셀 DataGrid 의 현재 값을 가져옵니다.

private void DataGrid1_Click(object sender,
    System.EventArgs e)
{
    DataTable dataGridTable =
        (DataTable)DataGrid1.DataSource;

    // Set the current row using the RowNumber
    // property of the CurrentCell.
    DataRow currentRow = dataGridTable.Rows[DataGrid1.CurrentCell.RowNumber];
    DataColumn column = dataGridTable.Columns[1];

    // Get the value of the column 1 in the DataTable.
    Console.WriteLine(currentRow[column, DataRowVersion.Current]);
}
Private Sub DataGrid1_Click _
    (ByVal sender As System.Object, ByVal e As System.EventArgs)

    Dim dataGridTable As DataTable = _
        CType(DataGrid1.DataSource, DataTable)

    ' Set the current row using the RowNumber 
    ' property of the CurrentCell.
    Dim currentRow As DataRow = dataGridTable.Rows( _
        DataGrid1.CurrentRowIndex)
    Dim column As DataColumn = dataGridTable.Columns(1)

    ' Get the value of the column 1 in the DataTable.
    label1.Text = currentRow(column, _
        DataRowVersion.Current).ToString()
End Sub

설명

version 속성과 RowState 혼동해서는 안 됩니다. 인수는 version 열의 원래 값을 기준으로 열에 포함된 데이터의 상태를 설명합니다.

속성을 설정하면 이벤트에서 예외가 발생하면 예외가 ColumnChanging 생성됩니다.

즉각적인 편집인 경우 생성할 수 있는 예외를 참조 EndEdit 하세요.

추가 정보

적용 대상

Item[Int32, DataRowVersion]

Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs

검색할 데이터의 지정된 버전 및 인덱스를 가진 열에 저장된 데이터를 가져옵니다.

public:
 property System::Object ^ default[int, System::Data::DataRowVersion] { System::Object ^ get(int columnIndex, System::Data::DataRowVersion version); };
public object this[int columnIndex, System.Data.DataRowVersion version] { get; }
member this.Item(int * System.Data.DataRowVersion) : obj
Default Public ReadOnly Property Item(columnIndex As Integer, version As DataRowVersion) As Object

매개 변수

columnIndex
Int32

열의 인덱스(0부터 시작)입니다.

version
DataRowVersion

원하는 행 버전을 지정하는 DataRowVersion 값 중 하나입니다. 가능한 값은 Default, Original, CurrentProposed입니다.

속성 값

데이터가 포함된 Object입니다.

예외

columnIndex 인수가 범위를 벗어난 경우

값과 열의 데이터 형식이 일치하지 않는 경우

행에 이 버전의 데이터가 없는 경우

삭제된 행에 값을 설정하려고 한 경우

예제

다음 예제에서는 개체의 속성을 통해 Item[] 열의 DataRow 현재 값을 가져옵니다.

Private Sub DataGrid1_Click _
    (ByVal sender As System.Object, ByVal e As System.EventArgs)
    
    ' Set the current row using the RowNumber property of the CurrentCell.
    Dim currentRow As DataRow = CType(DataGrid1.DataSource, DataTable). _
       Rows(DataGrid1.CurrentCell.RowNumber)

    ' Get the value of the column 1 in the DataTable.
    label1.Text = currentRow(1, DataRowVersion.Current).ToString()
End Sub

설명

메서드를 호출 BeginEdit 한 후에만 행을 만들거나 업데이트할 수 있습니다. 마찬가지로 EndEdit 편집을 커밋하려면 메서드를 호출해야 합니다. 메서드를 EndEdit 호출한 후 메서드를 AcceptChanges 호출하기 전에 제안된 원래 값과 새 값의 내부 표현이 저장됩니다. 따라서 를 호출AcceptChanges할 때까지 인수를 version 사용하여 필요한 열 값의 버전(또는 DataRowVersion.Proposed)을 DataRowVersion.Original 지정할 수 있습니다. 그러나 메서드를 호출 AcceptChanges 하는 즉시 열 버전이 로 되돌아갑니다 DataRowVersion.Original. 행이 새 경우 매개 변수를 전달 DataRowVersion.Default 하여 열의 기본값을 검색할 수도 있습니다. 를 전달할 DataRowVersion.Current때 속성은 버전이 무엇이든 현재 값을 반환합니다.

참고

메서드는 BeginEdit 데이터 바인딩된 컨트롤의 값을 변경하거나 DataRow 개체가 에 추가 DataRowCollectionEndEdit 되면 암시적으로 호출됩니다. 메서드는 개체의 메서드AcceptChanges, AcceptChanges 개체의 DataRowDataTable 메서드 또는 CancelEdit 메서드를 호출할 때 암시적으로 호출됩니다.

반면 열거형 CurrentDataRowVersion 메서드가 호출된 후 EndEdit 데이터 버전을 반환합니다.

인수는 version 속성과 RowState 혼동해서는 안 됩니다. 인수는 version 열의 원래 값을 기준으로 열에 포함된 데이터의 상태를 설명합니다. 속성은 RowState 부모 DataTable를 기준으로 전체 행의 상태를 설명합니다.

속성을 설정하면 이벤트에서 예외가 발생하면 예외가 ColumnChanging 생성됩니다.

즉각적인 편집인 경우 생성할 수 있는 예외를 참조 EndEdit 하세요.

적용 대상

Item[String, DataRowVersion]

Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs

명명된 열에 저장된 특정 버전의 데이터를 가져옵니다.

public:
 property System::Object ^ default[System::String ^, System::Data::DataRowVersion] { System::Object ^ get(System::String ^ columnName, System::Data::DataRowVersion version); };
public object this[string columnName, System.Data.DataRowVersion version] { get; }
member this.Item(string * System.Data.DataRowVersion) : obj
Default Public ReadOnly Property Item(columnName As String, version As DataRowVersion) As Object

매개 변수

columnName
String

열 이름입니다.

version
DataRowVersion

원하는 행 버전을 지정하는 DataRowVersion 값 중 하나입니다. 가능한 값은 Default, Original, CurrentProposed입니다.

속성 값

데이터가 포함된 Object입니다.

예외

columnName에서 지정한 열을 찾을 수 없는 경우

값과 열의 데이터 형식이 일치하지 않는 경우

행에 이 버전의 데이터가 없는 경우

행이 삭제된 경우

예제

다음 예제에서는 컨트롤의 클릭된 셀 DataGrid 에서 현재 버전의 데이터를 가져옵니다.

private void DataGrid1_Click(object sender, System.EventArgs e)
{
    // Set the current row using the RowNumber
    // property of the CurrentCell.
    DataRow currentRow =
        ((DataTable)(DataGrid1.DataSource)).
        Rows[DataGrid1.CurrentCell.RowNumber];

    // Print the current value of the column named "FirstName."
    Console.WriteLine(currentRow["FirstName",
        DataRowVersion.Current]);
}
Private Sub DataGrid1_Click _
    (ByVal sender As System.Object, ByVal e As System.EventArgs)
    
    ' Set the current row using the RowNumber property 
    ' of the CurrentCell.
    Dim currentRow As DataRow = _
        CType(DataGrid1.DataSource, DataTable). _
        Rows(DataGrid1.CurrentCell.RowNumber)

    ' Print the current value of the column named "FirstName."
    Console.WriteLine(currentRow("FirstName", _
        DataRowVersion.Current).ToString())
End Sub

설명

버전은 속성과 RowState 혼동해서는 안 됩니다. 인수는 version 열의 원래 값을 기준으로 열에 포함된 데이터의 상태를 설명합니다. 속성은 RowState 부모 DataTable를 기준으로 전체 행의 상태를 설명합니다.

속성을 설정하면 이벤트에서 예외가 발생하면 예외가 ColumnChanging 생성됩니다.

즉각적인 편집인 경우 생성할 수 있는 예외를 참조 EndEdit 하세요.

추가 정보

적용 대상