How to list in the listView the results of MySql

2

Code Structure

In this function below I try to get the content of the MySql database and passing it to a List<BDependente> lDep in the line where facade.listDependente(bDep);

Employee Method

        lvDependente.Columns.Add("Nome", 150, HorizontalAlignment.Left);
        lvDependente.Columns.Add("Parentesco", 70, HorizontalAlignment.Left);
        lvDependente.Columns.Add("Nascimento", 130, HorizontalAlignment.Left);

        lDep = facade.listDependente(bDep);            
        foreach (BDependente bDepe in lDep) {
            string[] row = {bDepe.Nome, bDepe.Grau_parentesco, bDepe.Data_nascimento };
            lvDependente.Items.Add(row);
        }
        lvDependente.View = View.Details;

The result of this is that only the last record of the bank leaves.

    
asked by anonymous 20.04.2016 / 11:55

1 answer

1

To populate a listview use this way:

    foreach (BDependente bDepe in lDep)
    {
        ListViewItem lvItem = new ListViewItem(bDepe.Nome);
        lvItem.SubItems.Add(bDepe.Grau_parentesco);
        lvItem.SubItems.Add(bDepe.Data_nascimento);
        lvDependente.Items.Add(lvItem);
    }
    
20.04.2016 / 15:01