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
Post a Comment