Foros del Web » Programación para mayores de 30 ;) » .NET »

Como llenar un ListView con objetos de tipo LIST<>

Estas en el tema de Como llenar un ListView con objetos de tipo LIST<> en el foro de .NET en Foros del Web. Hola Todos Amigos, Estoy empezando a conocer mas sobre c# y que mejor comenzando con un proyectito utilizando programacion en 3 capas . Mi problema ...
  #1 (permalink)  
Antiguo 02/12/2011, 13:16
 
Fecha de Ingreso: octubre-2006
Mensajes: 48
Antigüedad: 17 años, 5 meses
Puntos: 0
Pregunta Como llenar un ListView con objetos de tipo LIST<>

Hola Todos Amigos,

Estoy empezando a conocer mas sobre c# y que mejor comenzando con un proyectito utilizando
programacion en 3 capas .

Mi problema no se como llenar un listview pasando por mi 3 capas estoy un poco desorientado he buscado y no he encontrado si alquien me puede ayudar

EN MI CAPA DAL:

TENGO LO SIGUIENTE

Código:
 public List<MESubCategoria> ADListarGaleriaSubCategorias(String vchbyIdCatAll, String vchbyIdCat)
        {
            SqlConnection sqlCnx = null;
            SqlCommand sqlCmd = null;
            SqlDataReader sqlReader = null;


            List<MESubCategoria> lstMeGaleriaSubCategorias = new List<MESubCategoria>();

            try
            {
                String strConectionString = ConfigurationManager.ConnectionStrings["cnxDBCGallery"].ConnectionString;

                sqlCnx = new SqlConnection(strConectionString);
                sqlCmd = new SqlCommand("uspSubCategoria_LIST", sqlCnx);

                sqlCmd.CommandType = CommandType.StoredProcedure;

                sqlCmd.Parameters.Add("@vchbyIdAll", SqlDbType.NVarChar, 11);
                sqlCmd.Parameters.Add("@vchbyId", SqlDbType.NVarChar, 11);

                sqlCmd.Parameters[0].Value = UTHelper.ToDBNull(vchbyIdCatAll);
                sqlCmd.Parameters[1].Value = UTHelper.ToDBNull(vchbyIdCat);

                sqlCnx.Open();


                sqlReader = sqlCmd.ExecuteReader();

                if (sqlReader != null)
                {
                    if (sqlReader.HasRows)
                    {
                        while (sqlReader.Read())
                        {
                            MESubCategoria objMeSubCategoria = new MESubCategoria();

                            objMeSubCategoria.SubCategoriaId = sqlReader["SubCategoriaId"].ToString();
                            objMeSubCategoria.Nombre = sqlReader["Nombre"].ToString();



                            lstMeGaleriaSubCategorias.Add(objMeSubCategoria);
                        }
                    }


                }

            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (sqlCnx != null)
                {
                    sqlCnx.Dispose();
                }

                if (sqlCmd != null)
                {
                    sqlReader.Dispose();
                }

                if (sqlReader != null)
                {
                    sqlReader.Dispose();
                }

            }

            return lstMeGaleriaSubCategorias;


        }

CAPA NEGOCIOS :


Código:
public List<MESubCategoria> ListarBLGaleriaSubCategorias(String blvchbyIdCatAll, String blvchbyIdCat)
       {
           List<MESubCategoria> lstBLGaleriasSubCategorias = null;
           lstBLGaleriasSubCategorias = adSubCategorias.ADListarGaleriaSubCategorias(blvchbyIdCatAll, blvchbyIdCat);
           return lstBLGaleriasSubCategorias;
       }
CAPA PRESENTACION :

Aqui es el problema no se como
llenarlo estoy probando un foreach de la siguiente manera

Código:
 int x=0;

            foreach (BLSubCategoria blListarSubCateorias in  blListarSubCategorias.ListarBLGaleriaSubCategorias("%", null))
            {
                                 lstVistaCatalogo.Items.Add(blListarSubCategorias.ToString());
                x=x+1;
            }
aunque no tiene logica pero no se o estoy haciendo mal en mi capa de negocios

por favor si alguien me da una mano le agradeceria mucho


gracias
  #2 (permalink)  
Antiguo 02/12/2011, 14:31
Avatar de drako_darpan  
Fecha de Ingreso: octubre-2008
Ubicación: Sinaloa
Mensajes: 617
Antigüedad: 15 años, 6 meses
Puntos: 58
Respuesta: Como llenar un ListView con objetos de tipo LIST<>

Hola que tal, bueno pues yo lo e hecho anexandolo a un DataSource directamente el valor de la lista, pero para una columna combo y lo hice con lo siguiente:

ColumnaComboBox.DataSource = AsignarValorCombo.Secciones();

Secciones es mi List. Pruebalo haber si te funciona
  #3 (permalink)  
Antiguo 02/12/2011, 14:40
 
Fecha de Ingreso: octubre-2006
Mensajes: 48
Antigüedad: 17 años, 5 meses
Puntos: 0
Mensaje Respuesta: Como llenar un ListView con objetos de tipo LIST<>

Hola gracias por responder

pero el tema es que ListView no tiene la propiedad datasource.
  #4 (permalink)  
Antiguo 02/12/2011, 15:03
 
Fecha de Ingreso: noviembre-2011
Ubicación: Lima
Mensajes: 15
Antigüedad: 12 años, 4 meses
Puntos: 1
Respuesta: Como llenar un ListView con objetos de tipo LIST<>

Podría ser algo así:

Código:
            BLSubCategoria blListarSubCategorias = new BLSubCategoria();
            foreach (MESubCategoria objMESubCategoria in blListarSubCategorias.ListarBLGaleriaSubCategorias("%", null))
            {
                lstVistaCatalogo.Items.Add(objMESubCategoria.Nombre);
            }
Suerte,

Etiquetas: listview
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:42.