GetCurrentDataRow

//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();

Description

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.

Details

Double click on the code to select all.

 

;