How To Bind Objects To a DataGird ?

  • Thread starter Thread starter yaniv abo
  • Start date Start date
Y

yaniv abo

Hello.



How can I bind a list of objects to a DataGird?

I have a custom collection of Customer class



class Customer {

Public String Name;

Public String Addres;

….

}



How do I bind the collection to a data grid and the data grid will provide
the options to add\modify\delete customers from the collection.



If I put the Customers in an ArrayList data grid only display the data and
I’m unable to edit it.





Any help will be appreciated.





Yaniv abo

(e-mail address removed)
 
The ArrayList does not provide the interface you need in order to edit back.
The easiest way is just to populate a DataTable with one row per customer
and then bind the DataTable to your DataGrid instance. Then you can
edit/remove/add entries. When finished you can easily scan over the list of
rows in the data table and find the ones that are new (create a new matching
customer record), edited (update your existing customer record) or marked
for deletion (remove it from your customers collection).

Hope that helps
Phil Wright
Follow my microISV startup at....
http://componentfactory.blogspot.com
 
Back
Top