I have already used extensions for other components and did not give this problem, you are giving error only with DataGridView
. The component finds the extension, not the error, the error only displays when compiling the project.
When compiling is giving the following error :
Error 1 'System.Windows.Forms.DataGridView' does not contain a definition for 'GetColumnName' and no extension method 'GetColumnName' accepting a first argument of type 'System.Windows.Forms.DataGridView' could be found (are C: \ Users \ Nicola Bogar \ Desktop \ System \ MySolutionApp \ WindowsFormsApplication3 \ frmCadastroPais.cs 55 38 WindowsFormsApplication3
public static class ExtensionsDataGridView
{
/// <summary>
/// Obter os nomes das colunas da DataGridView.
/// </summary>
/// <param name="dgv"> Grid.</param>
/// <returns> Lista com os nomes das colunas. </returns>
public static List<string> ObterNomeDasColunas(this DataGridView dgv)
{
List<string> lista = new List<string>();
if (dgv == null)
return null;
if (dgv.ColumnCount > 0)
for (int i = 0; i < dgv.ColumnCount; i++)
lista.Add(dgv.Columns[i].Name);
return lista;
}
}
public class Teste
{
private void frmCadastroPais_Load(object sender, EventArgs e)
{
DataGridView dgv = new DataGridView();
dgv.DataSource = paisBindingSource.DataSource;
List<string> lista = dgv.ObterNomeDasColunas();
}
}