This chapter is from the book
The VisList Classes
The two VisList classes are really quite similar. The customer version operates on a ListBox and adds the names to it.
//A VisList class for the ListBox public class ProductList : VisList { private ListBox list; //----- public ProductList(ListBox lst) { list = lst; } //----- public void addLine(Product p) { list.Items.Add (p.getName() ); } //----- public void removeLine(int num) { if(num >=0 && num < list.Items.Count ){ list.Items.Remove (num); } } }
The ProductTable version of the VisList is quite similar except that it adds both the product name and quantity to the two columns of the grid.
public class GridList:VisList { private DataGrid grid; private DataTable dtable; private GridAdapter gAdapter; //----- public GridList(DataGrid grd) { grid = grd; dtable = new DataTable("Products"); DataColumn column = new DataColumn("ProdName"); dtable.Columns.Add(column); column = new DataColumn("Qty"); dtable.Columns.Add(column); grid.DataSource = dtable; gAdapter = new GridAdapter (grid); } //----- public void addLine(Product p) { gAdapter.Add (p); }