Loading data in listview C # [closed]

-2

I'm developing a solution in C # windows forms and would like an idea to be able to fetch the data from the database and load it into a listview. This loading would come from a combobox, in which I select an item and it brings related data from another table. I have not written any code yet, I'm looking for information on how to do this.

    
asked by anonymous 05.10.2017 / 15:23

1 answer

0
Hello, if you want to populate a listview from the database, you can do this:

        //Lista de um objeto
        List<MATERIA> objMateria = MateriaDAO.BuscarMateria((int)cmbTipo.SelectedValue);

        if (objMateria != null && objMateria.Count > 0)
        {
            //Limpa o listview antes de iniciar
            lstMateria.Items.Clear();

            foreach (MATERIA item in objMateria)
            {
                ListViewItem lv = new ListViewItem(item.CODIGO.ToString());
                lv.SubItems.Add(item.DESCRICAO);
                lstMateria.Items.Add(lv);
            }
        }
    
06.10.2017 / 21:01