Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List to datagridView datasource

I have a class :

    class TermekRendeles
    {
        public int TermekID;
        public string TermekNev;
        public int Mennyiseg;
    }

And a list of it:

    List<TermekRendeles> TermekLista;

Which consists of data like:

     1 | X | 2  
     2 | Y | 3

And I want it as a datasource of a DataGridView (and it to show the data like above). I have been trying different ways, wanted it in a ListBox first, but figured the DataGridView would be easier, but still can't get it. Most recent try:

bindingSource1.DataSource = TermekLista;
dataGridView1.DataSource = bindingSource1;

But it just doesn't do anything, it stays a blank dgw. What am I doing wrong?

like image 578
Saeq Avatar asked Mar 29 '26 19:03

Saeq


1 Answers

You have to use Properties, not Fields:

class TermekRendeles
{
  public int TermekID {get; set;}
  public string TermekNev {get; set;}
  public int Mennyiseg {get; set;}
}
like image 97
LarsTech Avatar answered Apr 01 '26 08:04

LarsTech



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!