I have difficulty showing objects as properties of other objects in Datagridview

Asked

Viewed 22 times

1

I have difficulties showing objects as properties of other objects in Datagridview I have the Address class which 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 {}

In the Object of Business 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);
  }

In the Form, I have a Textbox , A Search Button and Datagridview to display the data and select 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 Run Program does not display data in Datagriview, displays the following Message: Transference Object.Address.

I need a Help to solve this problem

  • Take a look at this site, to help you: http://www.macoratti.net/08/c_pdgv1.htm

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.