How to list Mysql results in the listview

Asked

Viewed 246 times

2

Structure of the Code

In this function below I try to grab the contents of the Mysql database and passing to a List<BDependente> lDep on the line where this facade.listDependente(bDep);

Official 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 bank record comes out.

1 answer

1


To popular 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);
    }
  • 1

    I implemented your tip but the result goes out in the unexpected way ! It is only bringing the last result.

  • The problem could be here:lDep = facade.listDependente(bDep);

  • this listDepending method is a query method in the Database, the problem should be there ? or is in the List<>

  • I implemented your tip but the result goes out in the unexpected way ! It is only bringing the last result, the result should be: Ikaro | Sobrinho(a) | 2016-04-13&#xA; Ikaro Sales | Neto(a) | 2016-04-05 How is it coming: [! [insert image description here][1]][1] [! [insert image description here][2][2] [1]: http://i.stack.Imgur.com/F1dyp.png [2]: http://i.stack.stackImgur.com/7pVWb.png

  • Checks whether the contents of the variable lDep is correct and if you do not have repeated data

  • I’m thinking the problem is in the bank’s consul

  • OK ! Thank you very much Tiago

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.