共用方式為


DataRowView.Item[] 屬性

定義

取得或設定指定資料行中的值。

多載

Item[Int32]

取得或設定指定資料行中的值。

Item[String]

取得或設定指定資料行中的值。

Item[Int32]

來源:
DataRowView.cs
來源:
DataRowView.cs
來源:
DataRowView.cs

取得或設定指定資料行中的值。

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

參數

ndx
Int32

資料行索引。

屬性值

資料行的值。

例外狀況

DataView 不允許編輯且 DataRowView 不是新的。

沒有對應至該索引值的資料行。

範例

下列範例會顯示 中每個 DataRowViewDataView專案的值。

private static void WriteViewRows(DataView view)
{
    int colCount = view.Table.Columns.Count;

    // Iterate through the rows of the DataView.
    foreach (DataRowView rowView in view)
    {
        // Display the value in each item of the DataRowView
        for (int i = 0; i < colCount; i++)
            Console.Write(rowView[i] + "\table");
        Console.WriteLine();
    }
}

Private Shared Sub WriteViewRows(view As DataView)
   Dim colCount As Integer = view.Table.Columns.Count

   ' Iterate through the rows of the DataView.
   For Each rowView As DataRowView In view
     ' Display the value in each item of the DataRowView
     For i As Integer = 0 To colCount - 1
        Console.Write(rowView(i) & vbTab)
     Next
     Console.WriteLine()
   Next
End Sub

適用於

Item[String]

來源:
DataRowView.cs
來源:
DataRowView.cs
來源:
DataRowView.cs

取得或設定指定資料行中的值。

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

參數

property
String

包含指定資料行的字串。

屬性值

資料行的值。

例外狀況

找不到具有指定名稱或關聯性的資料行。

-或-

DataView 不允許編輯且 DataRowView 不是新的。

設定值時不相符的 property

範例

下列範例會將文字附加至 中每個修改數據列中 DataView的數據行值。

private void SetDataRowView()
{
    DataView view = (DataView) dataGrid1.DataSource;

    // Set the filter to display only those rows that were modified.
    view.RowStateFilter=DataViewRowState.ModifiedCurrent;

    // Change the value of the CompanyName column for each modified row.
    foreach(DataRowView rowView in view)
    {
        rowView["CompanyName"] += " new value";
    }
}
Private Sub SetDataRowView()
     Dim view As DataView = CType(dataGrid1.DataSource, DataView)

     ' Set the filter to display only those rows that were modified.
     view.RowStateFilter = DataViewRowState.ModifiedCurrent

     ' Change the value of the CompanyName column for each modified row.
     Dim rowView As DataRowView
     For Each rowView In  view
         rowView.Item("CompanyName") = _
         rowView.Item("CompanyName").ToString() & " new value"
     Next rowView
End Sub

適用於