c# - loading data into datagridview from List<> customerlist -


i need populating datagridview. when debug can see has records, not shown in datagridview. here code (mind newbie in c#):

private void listcustomer_frm_load(object sender, eventargs e) {     datagridview custdgv = new datagridview();     customerlist = customerdb.getlistcustomer();     custdgv.datasource = customerlist;     cm = (currencymanager)custdgv.bindingcontext[customerlist];     cm.refresh(); } 

you're creating datagridview @ function scope , never add container. since nothing has reference it, disappears function exits.

you need this:

this.controls.add(custdgv); // add grid form display 

before function finishes. this:

private void listcustomer_frm_load(object sender, eventargs e) {     datagridview custdgv = new datagridview();     this.controls.add(custdgv); // add grid form display     customerlist = customerdb.getlistcustomer();     custdgv.datasource = customerlist;     cm = (currencymanager)custdgv.bindingcontext[customerlist];     cm.refresh(); } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -