DataRowView.Item[] Property

Definition

Gets or sets a value in a specified column.

Overloads

Item[Int32]

Gets or sets a value in a specified column.

Item[String]

Gets or sets a value in a specified column.

Item[Int32]

Source:
DataRowView.cs
Source:
DataRowView.cs
Source:
DataRowView.cs

Gets or sets a value in a specified column.

C#
public object this[int ndx] { get; set; }

Parameters

ndx
Int32

The column index.

Property Value

The value of the column.

Exceptions

The DataView doesn't allow edits and DataRowView is not new.

No column corresponds to that index value.

Examples

The following example displays the value in each item of each DataRowView in a DataView.

C#
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();
    }
}

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Item[String]

Source:
DataRowView.cs
Source:
DataRowView.cs
Source:
DataRowView.cs

Gets or sets a value in a specified column.

C#
public object this[string property] { get; set; }

Parameters

property
String

String that contains the specified column.

Property Value

The value of the column.

Exceptions

A column with the specified name or relation was not found.

-or-

The DataView doesn't allow edits and DataRowView is not new.

Unmatched property when setting a value.

Examples

The following example appends text to the value of a column in each modified row of a DataView.

C#
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";
    }
}

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1