ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

GetCurrentDataRow

The System.Windows.Forms.BindingSource has a property to return the current row as DataRowView object. But most of the time we need this as DataRow to manipulate the data. This extension method checks the Current property of BindingSource for nullity, returns null if it is null and returns the current Row as DataRow object if the Current property is not null.

Source

//Get the current row of binding source as datarow    
public static DataRow GetCurrentDataRow(this System.Windows.Forms.BindingSource bindingSource)
{
    if (bindingSource.Current == null) 
        return null;
    else 
        return ((DataRowView)bindingSource.Current).Row;
}

Example

DataRow currentRow = bindingSource.GetCurrentDataRow();

Author: V J Reddy

Submitted on: 9 okt. 2011

Language: C#

Type: System.Windows.Forms.BindingSource

Views: 18646