BindingSource between more than one class

2

I'm developing a system in C # windows form where I have my classes developed according to my database. My problem is that I am not getting my BindingSource to list the query data in a DataGridView. Here is the method that populates the BindingSource:

public List<Classes.clUsuarioSistema> ConsultaListaUsuario(int id)
        {
            try
            {
                clConexao.AbreConexao();
                MySqlCommand cmd = new MySqlCommand("SELECT * FROM USUARIOSISTEMA WHERE IDUSUARIO = @idusuario");
                cmd.Connection = clConexao.sqlConn;

                MySqlParameter parametroidUsuario = new MySqlParameter("@idusuario", MySqlDbType.Int32);
                parametroidUsuario.Value = id;
                cmd.Parameters.Add(parametroidUsuario);

                List<Classes.clUsuarioSistema> listaUsuarioSistema = new List<Classes.clUsuarioSistema>();

                MySqlDataReader drUsuarioSistema = cmd.ExecuteReader();

                while (drUsuarioSistema.Read())
                {
                    Classes.clUsuarioSistema vUsuarioSistema = new Classes.clUsuarioSistema();
                    Classes.clUsuario vUsuario = new Classes.clUsuario();
                    Classes.clSistema vSistema = new Classes.clSistema();
                    clSistemaDAO vSistemaDAO = new clSistemaDAO();
                    clUsuarioDAO vUsuarioDAO = new clUsuarioDAO();

                    vUsuario.idUsuario = Convert.ToInt32(drUsuarioSistema["IDRESPONSAVEL"].ToString());
                    vUsuario.Login = vUsuarioDAO.Consultar(vUsuario.idUsuario).Login;

                    vSistema.idSistema = Convert.ToInt32(drUsuarioSistema["IDSISTEMA"].ToString());
                    vSistema.Descricao = vSistemaDAO.Consultar(vSistema.idSistema).Descricao;

                    vUsuarioSistema.DataAtualizacao = Convert.ToDateTime(drUsuarioSistema["DATAATUALIZACAO"].ToString());
                    vUsuarioSistema.Responsavel = vUsuario;
                    vUsuarioSistema.Sistema = vSistema;

                    listaUsuarioSistema.Add(vUsuarioSistema);
                }
                return listaUsuarioSistema.ToList();
            }
            catch
            {
                clConexao.FechaConexao();
                throw;
            }
            finally
            {
                clConexao.FechaConexao();
            }
        }

Where this return I bind to the BindingSource of the form.

The result is as follows:

What do I need to do to get Grid the data I need?

    
asked by anonymous 26.08.2015 / 18:06

2 answers

0

I do not know if this is the correct way to solve this problem, but the solution I found was to make an override, as advised by TobyMosque. Thank you for your cooperation.

    
03.09.2015 / 14:52
2

You are passing the object and not the property .

vUsuarioSistema.Responsavel = vUsuario;
vUsuarioSistema.Sistema = vSistema;

In this case (I do not know your class), you should assign it as follows:

vUsuarioSistema.Responsavel = vUsuario.Nome;
vUsuarioSistema.Sistema = vSistema.Nome;

If Nome is the property you want to display.

As quoted by Jeferson, DateConnection in catch is not necessary, since finally will always run regardless of whether an error occurred or not.

    
26.08.2015 / 18:14