public Grid(DataGrid TheGrid) { try { //get the Data in the grid DataTable TableGrid = null; if (TheGrid.DataSource.GetType()==typeof(DataView)) { DataView ViewGrid = (DataView)TheGrid.DataSource; TableGrid = ViewGrid.Table; } else { TableGrid = (DataTable)TheGrid.DataSource; } //set number of rows rows = TableGrid.DefaultView.Count; //set number of columns //first check if the grid has tablestyle and columnstyle //check for table styles if (TheGrid.TableStyles.Count==0) { //create table style and column style CreateColumnStyles(TheGrid,TableGrid); } else { //create column styles if there are none if (TheGrid.TableStyles[TableGrid.TableName].GridColumnStyles.Count==0) CreateColumnStyles(TheGrid,TableGrid); } //set number of columns columns = TheGrid.TableStyles[TableGrid.TableName].GridColumnStyles.Count; Cells = new Cell[Rows,Columns]; //Copy Cells for (int i=0;i<Rows;i++) { for (int j=0;j<Columns;j++) { Cells[i,j] = new Cell(i,j,TheGrid.Font,TheGrid.TableStyles[TableGrid.TableName].GridColumnStyles[j].Alignment,TheGrid.GetCellBounds(i,j),TheGrid[i,j].ToString()); } Height +=Cells[i,0].Height; } //init number of columns to headers Headers = new Header[Columns]; SetHeaders(TheGrid,TableGrid); //define grid colors SetColors(TheGrid); } catch (Exception e) { Console.WriteLine(e.Message); } }
/// <summary> /// Set a new value for a cell /// </summary> public Cell this[Cell cell] { set {Cells[cell.RowNumber,cell.ColumnNumber]=value;} }