1
I’ve used Xtensions for other components and did not give this problem, is giving the error only with the DataGridView. The component finds the extension, and not the error, the error shows only when building the project.
When compiling is giving the following error:
Error 1 'System.Windows.Forms.Datagridview' does not contain a Definition for 'Get Column Names' and no Extension method 'Get Column Names' Accepting a first argument of type 'System.Windows.Forms.Datagridview' could be found (are you Missing a using Directive or an Assembly Reference?) 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();
}
}
Solved friend, strange this right, your code has not changed almost anything of mine, just the way to get the name of the columns. I think it really should be something related to namespace.. Thank you very much anyway.
– Nicola Bogar