I'm using the following code to include items in a list and show the same in my DataGridView
:
PedidodetalheOffline item = new PedidodetalheOffline(); //crio um novo item
item.IdOffline = id; //seto o id
item.PedidoOffline = numero; //seto o numero do pedido
item.ItemOffline = iditem; //seto o item
pedido.Add(item); //adiciono o item à lista "pedido"
id++; //incremento a variavel id para nao repetir
MessageBox.Show(pedido.Count().ToString()); //quantidade de intens que tem na lista
gridPedido.DataSource = pedido; //passo a lista pro DataGridView
This is the button code that includes items in the list and passes to DataGridView
. What happens is that the first time it works (the first item is shown within DataGridView
), but from the second, it does not work (it continues to show only the first). I've included MessageBox
to confirm that the items are being added to the list and have confirmed that they are.
What can it be? Do you have any commands to update the list or DataGridView
each time I add a new item?