//get all authors and populate DG_words with all authors, in order to fill it with values public void add_author_columns_to_DG_words(Collection <string> authors) { foreach (var author in authors) { DataGridViewColumn temporary_author_col = new DataGridViewColumn(); DataGridViewCell temporary_cell = new DataGridViewTextBoxCell(); temporary_author_col.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells; temporary_author_col.HeaderText = author; temporary_author_col.Name = "DG_words_col_" + author; temporary_author_col.ReadOnly = false; temporary_author_col.SortMode = DataGridViewColumnSortMode.Automatic; temporary_author_col.Width = 50; temporary_author_col.CellTemplate = temporary_cell; if (author == "System") { temporary_author_col.Visible = false; } DG_words.Invoke(new MethodInvoker(delegate { DG_words.Columns.Add(temporary_author_col); })); } }
void fill_author_columns_of_DG_words(Dictionary <string, Word> words) { add_author_columns_to_DG_words(authors); DataGridViewRow row = new DataGridViewRow(); int i = 2; //name column1 to assign a value DG_words.Columns[0].Name = "Word"; //name column2 to assign a value DG_words.Columns[1].Name = "Sum"; //counter to sort midway through int counter = 1; //for every word in words //for loop represents one row-fill foreach (var word in words.Keys) { DG_words.Invoke(new MethodInvoker(delegate { row = DG_words.Rows[DG_words.Rows.Add()]; })); DG_words.Invoke(new MethodInvoker(delegate { row.Cells["Word"].Value = word; })); row.Cells["Sum"].Value = words[word].get_totaloccurrences(); i = 2; //for every author in a word foreach (var author_dict in words[word].get_author_occurrence()) { //name column x to assign a value DG_words.Invoke(new MethodInvoker(delegate { DG_words.Columns[i].Name = author_dict.Key; })); row.Cells[author_dict.Key].Value = words[word].get_author_occurrence()[author_dict.Key]; i++; } counter++; //temporarily sort if (counter == 50) { DG_words.Invoke(new MethodInvoker(delegate { DG_words.Sort(DG_words.Columns[1], ListSortDirection.Descending); })); } } //finally sort DG_words.Invoke(new MethodInvoker(delegate { DG_words.Sort(DG_words.Columns[1], ListSortDirection.Descending); })); }