Add line to Datagrid with Datasource defined

Asked

Viewed 449 times

3

I have a DataGridView who has the DataSource setate with List<MinhaClasse> and would like to add a new line to it.

I know this is not possible using the method AddRow() of DataGrid.

Is there any way I can do this?

1 answer

3


It is possible to do this, setando one BindindList<> as DataSource. So whenever an item is added from BindingList<> it will be automatically inserted into DataGridView.

var source = new BindingList<MinhaClasse>();
dataGridView1.DataSource = source;
source.Add(new MinhaClasse { Nome = "João", Idade = 32 });    

Browser other questions tagged

You are not signed in. Login or sign up in order to post.