I have difficulty showing Objects as properties of other objects in the DataGridView

1

I have difficulty displaying Objects as properties of other objects in the DataGridView I have the Address Class that is a property of the Vendor class

In the Transfer Area

public class Endereco {
 public string Rua {
  get;
  set;
 }
 public string Bairro {
  get;
  set;
 }
 public string Cidade {
  get;
  set;
 }
}

public class Fornecedor {
 public string Codigo {
  get;
  set;
 }
 public string Nome {
  get;
  set;
 }
 public Fornecedor Fornecedor {
  get;
  set;
 }
}

public class FornecedorCollection: List {}

No Business Object I have:

public FornecedorCollection ConsultarFornecedorCod(int Codigo) {
  try {
   FornecedorCollection fornecedorCollection = new FornecedorCollection();

   acessarSQL.LimparParametros();
   acessarSQL.AdicionarParametros("@Coddigo", Codido);

   DataTable dataTablefornecedor = acessarSQL.ExecConsulta(CommandType.StoredProcedure, "uspFornConsultaCod");

   foreach(DataRow linha in dataTableFornecedor.Rows) {
    Fornecedor fornecedor = new Fornecedor();

    Fornecedor.Codigo = Convert.ToInt32(linha["codigo"]);
    Fornecedor.Nome = Convert.ToString(linha["Nome"]);

    Fornecedor.Endereco = New Endereco()

    Fornecedor.Endereco.Rua = Convert.ToString(linha["Rua"]);
    Fornecedor.Endereco.Bairro = Convert.ToString(linha["Bairro"]);
    Fornecedor.Endereco.Cidade = Convert.ToString(linha["Cidade"]);

    fornecedorCollection.Add(fornecedor);

   }

   return fornecedorCollection;
  } catch (Exception ex) {
   throw new Exception("Não foi Possivél consultar " + ex.Message);
  }

On the Form, I have a Textbox, a Search Button, and the DataGridView to show the data and select it with the following code:

public partial class FrmFornecedor: Form {
 public FrmFornecedor() {
  InitializeComponent();
  dataGridViewForn.AutoGenerateColumns = false;

 }

 private void BtnPesqForn_Click(object sender, EventArgs e) {
  ActualizarDataGridForn();
 }

 // criar uma rotina para actualizar o datagrid private void ActualizarDataGridForn() { FornecedorNegocios FornecedorNegocios = new FornecedorNegocios();

 FornecedorCollection FornecedorCollection = new FornecedorCollection();
 FornecedorCollection = FornecedorNegocios.ConsultarFornecedorDesig(TxtPesqForn.Text);
}

dataGridViewForn.DataSource = null;
dataGridViewForn.DataSource = FornecedorCollection;

dataGridViewForn.Update();
dataGridViewForn.Refresh();
}
}

When Running the Program does not show the data in the DataGriView, it shows the following message: Transfer Object.Endereco.

I need a Help to solve this problem

    
asked by anonymous 22.09.2016 / 05:36

0 answers