Difficulty in popularizing GridView

1

I have a screen that I query clients and fills in a grid with the information that comes from the database, my project is layered up to where I'm working, but I can not fill in > grid with some information, I have the following situation inside for each :

 Cliente cliente = new Cliente();

 cliente.Pessoa = new Pessoa();
 cliente.Pessoa.IdPessoa = Convert.ToInt32(linha["IdPessoaCliente"]);
 cliente.Pessoa.Nome = Convert.ToString(linha["Nome"]);
 cliente.DataCadastro = Convert.ToDateTime(linha["DataCadastro"]); 
 cliente.DataAlteracao = Convert.ToDateTime(linha["DataAlteracao"]);
 cliente.LimiteCompra = Convert.ToDecimal(linha["LimiteCompra"]);
 cliente.Ativo = Convert.ToBoolean(linha["Ativo"]);

 cliente.Pessoa.PessoaTipo = new PessoaTipo();
 cliente.Pessoa.PessoaTipo.IdPessoaTipo = Convert.ToInt32(linha["IdPessoaTipo"]);
 cliente.Pessoa.PessoaTipo.Descricao = Convert.ToString(linha["Descricao"]);

 clienteColecao.Add(cliente);
The grid fields that come directly from the client such as cliente.DataCadastro loads normal, but what is cliente.Pessoa.IdPessoa in grid is written "transfer object ", or if I customize the grid nothing comes and when debug I see that cliente.Pessoa.IdPessoa IdPessoa has the correct value but Pessoa is written Objeto transfer exactly what goes into the grid .

    
asked by anonymous 09.02.2015 / 23:34

3 answers

1

Are you populating your DataGridView?

The DataGridView has a property called DataSource. In it you get the source of your data.

It would be something like:

dgvClientes.DataSource = cliente.Listagem();

Check:

DataGridView - MSDN

    
20.02.2015 / 16:19
1

The Client.Person will not appear because there is no representation of the objects of the class. In simplistic terms the objects in the cells show the result of the ToString ().

The question you can ask is what do you expect the Person class to show in the cell?

    
20.02.2015 / 16:28
1

See if the example below helps with something:

public void MostrarClientes()
{
        string StrCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Desktop\Oi\Testando.accdb";
        string sql = "SELECT * FROM Cliente";

        OleDbConnection Con = new OleDbConnection(StrCon);
        OleDbDataAdapter da = new OleDbDataAdapter(sql, Con);
        DataTable dt = new DataTable();
        da.Fill(dt);
        dataGridView1.DataSource = dt;
}

Another example:

protected void CarregarDataGridView(String parametro)
{
  MySqlConnection conn = new MySqlConnection("Server=NomeServidor;Database=Teste;Uid=root;Pwd=sua_senha;");
  conn.Open();

  try
  {
    MySqlCommand cmd = new MySqlCommand("SELECT * FROM TABELA WHERE CAMPO=@CAMPO", conn);
    cmd.Parameters.Add(new MySqlParameter("@CAMPO", parametro));

    MySqlDataReader reader = cmd.ExecuteReader();
    DataTable table = new DataTable();

    table.Load(reader);

    this.dataGridView1.DataSource = table;

    table.Dispose();
    reader.Close();
    reader.Dispose();

  }
  catch (Exception ex)
  {
    MessageBox.Show(ex.Message);
  }
  finally
  {
    conn.Close();
    conn.Dispose();
  }
}
    
01.03.2015 / 23:54