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


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.


//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;
        return ((DataRowView)bindingSource.Current).Row;


DataRow currentRow = bindingSource.GetCurrentDataRow();

Author: V J Reddy

Submitted on: 9 okt 2011

Language: C#

Type: System.Windows.Forms.BindingSource

Views: 18164