I am trying to bind data to a datagridview in C#. How can I bind table data to a gridview please.
Below is my code used.
Getting all data.
public IEnumerable<MailingList> getAllAddress()
{
return Entities.MailingLists.AsEnumerable();
}
Datasource
dgvAddresses.DataSource = new AddressAccess().getAllAddress();
For some reason nothing appears. How can I bind the data please.
You can do it using a Binding source:
var source = new BindingSource();
source.DataSource = new AddressAccess().getAllAddress().ToList();
dgvAddresses.AutoGenerateColumns=true;
dgvAddresses.DataSource = source;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With