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


This extension retrieves from the current row in a DataGridView a column value as a string. There are three ways to call this extension 1. No parameters returned the current active column for the active row. 2. Pass Column name for current active row. 3. Pass Column index for current active row.


<Runtime.CompilerServices.Extension()> _
Function CurrentRowCellValue(ByVal GridView _
         As DataGridView) As String
    Return GridView.Rows(GridView.CurrentRow.Index) _
End Function

<Runtime.CompilerServices.Extension()> _
Function SelectedColumnNameIndex(ByVal GridView _
         As DataGridView) As Int32
    Return GridView.Columns(GridView _
End Function

<Runtime.CompilerServices.Extension()> _
Function CurrentRowCellValue(ByVal GridView As DataGridView, _
                             ByVal ColumnIndex As Integer) As String
    Return GridView.Rows(GridView.CurrentRow.Index) _
End Function


Private Sub Button1_Click() Handles Button1.Click
    ' get current active cell
    ' ask for company column, index 1
    ' ask for company by index
End Sub

Author: Kevin S Gallagher

Submitted on: 26 okt 2009

Language: VB

Type: System.Windows.Forms.DataGridview

Views: 4574