public void addRow(CustomPage page) { names.Add(page.PageName); ObjectTableRow objectRow = new ObjectTableRow(page, Color.White); //Make the individual cells for this object, using the provided parameter Names to obtain the desired values. TableCell indexCell = new TableCell(); Label indexLabel = new Label(); indexLabel.Text = page.SortIndex.ToString(); indexCell.Controls.Add(indexLabel); objectRow.Controls.Add(indexCell); ObjectTableCell pageNameCell = new ObjectTableCell(objectRow, "PageName", false); TextBox nameTextBox = new TextBox(); nameTextBox.Text = page.PageName; pageNameCell.Controls.Add(nameTextBox); objectRow.ObjectCells.Add(pageNameCell); objectRow.Controls.Add(pageNameCell); TableCell upCell = new TableCell(); Button upButton = new Button(); upButton.Text = "+"; upButton.Click += new EventHandler(upButton_Click); upCell.Controls.Add(upButton); objectRow.Cells.Add(upCell); TableCell downCell = new TableCell(); Button downButton = new Button(); downButton.Text = "-"; downButton.Click += new EventHandler(downButton_Click); downCell.Controls.Add(downButton); objectRow.Cells.Add(downCell); TableCell deleteCell = new TableCell(); Button deleteButton = new Button(); deleteButton.Text = "Delete"; deleteButton.Click += new EventHandler(deleteButton_Click); deleteCell.Controls.Add(deleteButton); objectRow.Cells.Add(deleteCell); //Add to table this.Rows.Add(objectRow); objectRows.Add(objectRow); if (objectRow.Color == Color.Empty) { objectRow.Visible = false; } }
public void addRow(T newObject, Color color) { //Make the remaining rows, where each row contains one object from the provided List<T> ObjectTableRow objectRow = new ObjectTableRow(newObject, color); //Check if Object should be player editable bool readOnly = false; if (viewOnly && !exceptions.Contains((Object)newObject)) { readOnly = true; } //Make the individual cells for this object, using the provided parameter Names to obtain the desired values. for (int column = 0; column < columns; column++) { ObjectTableCell objectCell = new ObjectTableCell(objectRow, parameters[column], readOnly); objectRow.Cells.Add(objectCell); objectRow.ObjectCells.Add(objectCell); } //Make Delete button if not view only if (!viewOnly) { TableCell deleteCell = new TableCell(); Button deleteButton = new Button(); deleteButton.Text = "Delete"; deleteButton.Click += new EventHandler(deleteButton_Click); deleteCell.Controls.Add(deleteButton); objectRow.Cells.Add(deleteCell); } //Add to table this.Rows.Add(objectRow); objectRows.Add(objectRow); if (color == Color.Empty) { objectRow.Visible = false; } }
//Takes a list of any kind of objects, an array with the desired parameters to form the columns, and an optional Dictionary of types/colors so you can color code by inherritance. public ObjectTable(Dictionary <T, Color> objects, string[] parameters, bool viewOnly = false, List <Object> exceptions = null) { this.columns = parameters.Length; this.colors = objects; this.parameters = parameters; this.viewOnly = viewOnly; this.exceptions = exceptions; //Generate Table this.ID = "objectTable"; //Needed so javascript can find the table to sort columns. Should use a better way. //Make Header Row, and Buttons so can be sorted by whatever column I want. Uses JS to sort entire rows. TableRow header = new TableRow(); for (int i = 0; i < columns; i++) { TableCell headerColumn = new TableCell(); Button sortButton = new Button(); sortButton.Text = parameters[i]; sortButton.CssClass = "fullWidth"; sortButton.OnClientClick = "return sortTable(" + i + ")"; headerColumn.Controls.Add(sortButton); header.Cells.Add(headerColumn); } this.Rows.Add(header); if (colors.Count == 0) { header.Visible = false; } else { header.Visible = true; } //Make the remaining rows, where each row contains one object from the provided List<T> foreach (KeyValuePair <T, Color> entry in colors) { ObjectTableRow objectRow = new ObjectTableRow(entry.Key, entry.Value); //Check if Object should be player editable bool readOnly = false; if (viewOnly && !exceptions.Contains((Object)entry.Key)) { readOnly = true; } //Make the individual cells for this object, using the provided parameter Names to obtain the desired values. for (int column = 0; column < columns; column++) { ObjectTableCell objectCell = new ObjectTableCell(objectRow, parameters[column], readOnly); objectRow.Cells.Add(objectCell); objectRow.ObjectCells.Add(objectCell); } //Make Delete button if not view only if (!viewOnly) { TableCell deleteCell = new TableCell(); Button deleteButton = new Button(); deleteButton.Text = "Delete"; deleteButton.Click += new EventHandler(deleteButton_Click); deleteCell.Controls.Add(deleteButton); objectRow.Cells.Add(deleteCell); } //Add to table this.Rows.Add(objectRow); objectRows.Add(objectRow); if (objectRow.Color == Color.Empty) { objectRow.Visible = false; } } }
//Takes a list of any kind of objects, an array with the desired parameters to form the columns, and an optional Dictionary of types/colors so you can color code by inherritance. public PageTable(CustomPageList pages) { this.pages = pages; //Generate Table this.ID = "objectTable"; //Needed so javascript can find the table to sort columns. Should use a better way. //Make Header Row, and Buttons so can be sorted by whatever column I want. Uses JS to sort entire rows. TableRow header = new TableRow(); TableCell indexColumn = new TableCell(); indexColumn.Text = "Index"; header.Cells.Add(indexColumn); TableCell nameColumn = new TableCell(); nameColumn.Text = "Page Name"; header.Cells.Add(nameColumn); this.Rows.Add(header); if (pages.Pages.Count == 0) { header.Visible = false; } else { header.Visible = true; } //Make the remaining rows, where each row contains one object from the provided List<T> for (int i = 0; i < pages.Pages.Count; i++) { CustomPage page = pages.Pages[i]; ObjectTableRow objectRow = new ObjectTableRow(page, Color.White); if (page.MarkedForDeletion == true) { objectRow.Visible = false; } //Make the individual cells for this object, using the provided parameter Names to obtain the desired values. TableCell indexCell = new TableCell(); Label indexLabel = new Label(); indexLabel.EnableViewState = false; indexLabel.CssClass = "regularFont"; indexLabel.Text = page.SortIndex.ToString(); indexCell.Controls.Add(indexLabel); objectRow.Controls.Add(indexCell); ObjectTableCell pageNameCell = new ObjectTableCell(objectRow, "PageName", false); objectRow.ObjectCells.Add(pageNameCell); objectRow.Controls.Add(pageNameCell); TableCell upCell = new TableCell(); Button upButton = new Button(); upButton.Text = "+"; upButton.Click += new EventHandler(upButton_Click); upCell.Controls.Add(upButton); objectRow.Cells.Add(upCell); TableCell downCell = new TableCell(); Button downButton = new Button(); downButton.Text = "-"; downButton.Click += new EventHandler(downButton_Click); downCell.Controls.Add(downButton); objectRow.Cells.Add(downCell); TableCell deleteCell = new TableCell(); Button deleteButton = new Button(); deleteButton.Text = "Delete"; deleteButton.Click += new EventHandler(deleteButton_Click); deleteCell.Controls.Add(deleteButton); objectRow.Cells.Add(deleteCell); //Add to table this.Rows.Add(objectRow); objectRows.Add(objectRow); } }
private void loadNPCTable() { NPCsTable dbNpcTable = new NPCsTable(new DatabaseConnection()); npcs = dbNpcTable.getGameNPCs(game.GameID); String[] parameters = new string[] { "Name", "Sex", "Race", "Location" }; //Generate Table table = new Table(); table.ID = "objectTable"; TableRow header = new TableRow(); TableCell blankColumn = new TableCell(); header.Cells.Add(blankColumn); //Make Header Columns for (int i = 0; i < parameters.Length; i++) { TableCell headerColumn = new TableCell(); Button sortButton = new Button(); sortButton.Text = parameters[i]; sortButton.CssClass = "fullWidth"; sortButton.OnClientClick = "return sortTable(" + (i + 1) + ")"; headerColumn.Controls.Add(sortButton); header.Cells.Add(headerColumn); } table.Rows.Add(header); if (npcs.Count == 0) { header.Visible = false; } else { header.Visible = true; } //Make the remaining rows, where each row contains one object from the provided List<T> foreach (NPC npc in npcs) { ObjectTableRow objectRow = new ObjectTableRow(npc, Color.White); //Check if Object should be player editable bool readOnly = true; //Add select radio button TableCell selectCell = new TableCell(); RadioButton isSelected = new RadioButton(); isSelected.Attributes.Add("value", npc.NpcID.ToString()); isSelected.GroupName = "npcGroup"; isSelected.AutoPostBack = true; isSelected.CheckedChanged += new EventHandler(npcButton_Click); selectCell.Controls.Add(isSelected); radioButtons.Add(isSelected); objectRow.Controls.Add(selectCell); //Make the individual cells for this object, using the provided parameter Names to obtain the desired values. for (int column = 0; column < parameters.Length; column++) { ObjectTableCell objectCell = new ObjectTableCell(objectRow, parameters[column], readOnly); objectRow.Cells.Add(objectCell); objectRow.ObjectCells.Add(objectCell); } //Add to table table.Rows.Add(objectRow); objectRows.Add(objectRow); if (objectRow.Color == Color.Empty) { objectRow.Visible = false; } } NPCTablePlaceHolder.Controls.Add(table); }