1

I got a list of 'word' objects called 'data', I got a function that edits one element in this list and refreshes the DataGridView fine, but when i try to add an item from it and execute a Refresh(), it doesn't add it to the grid.

public void edit (string en, string fr, int index)
{
    data[index].english = en;
    data[index].french = fr;
    wordGrid.Refresh();

} // Currently works

private void quickAddButton_Click(object sender, EventArgs e)
{
    string fr = addFrenchText.Text;
    string eng = addEnglishText.Text;
    string toWrite = eng + "_" + fr;
    //Adding the word in the current database
    word wordToWrite = new word(toWrite);
    data.Add(wordToWrite);
    wordGrid.Refresh();
} //Doesn't add the occurence
Yooooomi
  • 895
  • 1
  • 8
  • 20
  • 1
    Use a `BindingList` instead of `List`. Or set `grid.DataSource = null;` then `grid.DataSource = list;` again. – Reza Aghaei Oct 04 '16 at 19:31
  • Thanks ! null to 'data' list worked :D ! – Yooooomi Oct 04 '16 at 19:36
  • Here is a similar question for `ListBox`: [Connect List to a ListBox](http://stackoverflow.com/questions/33623991/connect-listt-to-a-listbox) – Reza Aghaei Oct 04 '16 at 19:38
  • 2
    __Do not__ call a `DataGridView`a `GridView` or a `DataGrid` and vice versa!! This is wrong and confusing as those are different controls. Always call things by their __right__ name! – TaW Oct 04 '16 at 19:39
  • Please add an answer so I can validate it haha – Yooooomi Oct 04 '16 at 19:48

0 Answers0