/// <summary> /// Displays in the control the table "tableToPut" and returns the tuple in which the first element /// contains the table given by the user and the second one the dialog result. /// Throws an exception if the number of rows within the table "tableToPut" /// </summary> /// <param name="tableToPut"></param> /// <returns></returns> public Tuple <MyTable, DialogResult> GetTableWithHeader(MyTable tableToPut, bool dialog = true, System.Windows.Forms.Form myForm = null) { if (tableToPut.Content.Count() <= 1) { throw new ArgumentException("A table with 0 or 1 row passed to GetTableWithHeader"); } for (int Iterator = 1; Iterator <= tableToPut.ColumnsInFirstRow(); Iterator++) { MyGridView2.Columns.Add(tableToPut.Content[0][Iterator - 1], tableToPut.Content[0][Iterator - 1]); } MyGridView2.RowCount = tableToPut.RowCount() - 1; foreach (int RowIterator in tableToPut.NonHeaderRowNumbers()) { // if (MyGridView2[0, RowIterator - 1 - 1].Value is null) continue; for (int ColumnIterator = 1; ColumnIterator <= tableToPut[RowIterator - 1].Count(); ColumnIterator++) { MyGridView2[ColumnIterator - 1, RowIterator - 1 - 1].Value = tableToPut.Content[RowIterator - 1][ColumnIterator - 1]; } } DialogResult MyOutcome = DialogResult.OK; if (dialog) { MyOutcome = ShowDialog(); } else { Show(myForm); } // 000000000000000000 // DialogResult MyOutcome = modal? ShowDialog():Show(this); List <List <string> > MyContent = new List <List <string> >(); MyContent.Add(tableToPut.Content[0]); if (MyOutcome == DialogResult.OK) { for (int Iterator = 1; Iterator <= MyGridView2.RowCount; Iterator++) { if (MyGridView2[0, Iterator - 1].Value is null) { continue; } List <string> MyRowItem = new List <string>(); for (int ColumnIterator = 1; ColumnIterator <= MyGridView2.ColumnCount; ColumnIterator++) { string ValueToAdd = (MyGridView2[ColumnIterator - 1, Iterator - 1].Value is null) ? "" : MyGridView2[ColumnIterator - 1, Iterator - 1].Value.ToString(); MyRowItem.Add(ValueToAdd); } MyContent.Add(MyRowItem); } } MyTable MyOutput = new MyTable(MyContent); return(new Tuple <MyTable, DialogResult>(MyOutput, MyOutcome)); }
/// <summary> /// Puts the table "toPut" into the grid /// </summary> /// <param name="toPut"></param> /// <returns></returns> public void DisplayTable(MyTable tableToPut) { for (int Iterator = 1; Iterator <= tableToPut.ColumnsInFirstRow(); Iterator++) { MyGridView2.Columns.Add(tableToPut.Content[0][Iterator - 1], tableToPut.Content[0][Iterator - 1]); } MyGridView2.RowCount = tableToPut.RowCount(); foreach (int RowIterator in tableToPut.NonHeaderRowNumbers()) { for (int ColumnIterator = 1; ColumnIterator <= tableToPut[RowIterator - 1].Count(); ColumnIterator++) { MyGridView2[ColumnIterator - 1, RowIterator - 1 - 1].Value = tableToPut.Content[RowIterator - 1][ColumnIterator - 1]; } } Show(); }