This topic has not yet been rated - Rate this topic

DataGridViewCellParsingEventArgs.ColumnIndex Property

Note: This property is new in the .NET Framework version 2.0.

Gets the column index of the cell data that requires parsing.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public int ColumnIndex { get; }
/** @property */
public int get_ColumnIndex ()

public function get ColumnIndex () : int

Property Value

The column index of the cell that was changed.

Use the ColumnIndex property to obtain an index into the Columns property of a DataGridView.

The following code example demonstrates using ColumnIndex to discover if the changed cell is in the date column.

// Handling CellParsing allows one to accept user input, then map it to a different
// internal representation.
private void dataGridView1_CellParsing(object sender, DataGridViewCellParsingEventArgs e)
{
    if (this.dataGridView1.Columns[e.ColumnIndex].Name == "Release Date")
    {
        if (e != null)
        {
            if (e.Value != null)
            {
                try
                {
                    // Map what the user typed into UTC.
                    e.Value = DateTime.Parse(e.Value.ToString()).ToUniversalTime();
                    // Set the ParsingApplied property to 
                    // Show the event is handled.
                    e.ParsingApplied = true;

                }
                catch (FormatException)
                {
                    // Set to false in case another CellParsing handler
                    // wants to try to parse this DataGridViewCellParsingEventArgs instance.
                    e.ParsingApplied = false;
                }
            }
        }
    }
}

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.