How to delete the line that automatically generates in a gridView windowns form

1

I have gridView that as soon as it is populated with data, it always generates one more line. How do I remove it?

Obs. The grid columns are generated dynamically.

if(objPed.ConsultarPedido(Metodos.empresa,txtNumPedido.Text)>0){ClienteobjCli=newCliente();ProdutosobjProd=newProdutos();objCli.ConsultarCliente(objPed.PedCliente);SetarPropriedades(objPed,objCli);objPed.dtItensPedido=objPed.ConsultarItens();DataTabledt=newDataTable();dt.Columns.Add("Produtos");
                        dt.Columns.Add("Descrição");
                        dt.Columns.Add("Unid.");
                        dt.Columns.Add("Qtde.");
                        dt.Columns.Add("Vlr. Unit.");
                        dt.Columns.Add("Vlr. Desconto");
                        dt.Columns.Add("Vlr. Total");
                        dt.Columns.Add("Reorder");
                        dt.Columns.Add("Tipo Item");
                        dt.Columns.Add("Qtd.Dig.");
                        for (int i = 0; i < objPed.dtItensPedido.Rows.Count; i++)
                        {
                            var tempRow = dt.NewRow();
                            dt.Rows.Add(tempRow);
                            dt.Rows[i]["Produtos"] = objPed.dtItensPedido.Rows[i]["ItPProduto"];
                            dt.Rows[i]["Descrição"] = objPed.dtItensPedido.Rows[i]["ItPDescrProd"];
                            dt.Rows[i]["Unid."] = objPed.dtItensPedido.Rows[i]["ItPUnidProd"];
                            dt.Rows[i]["Qtde."] = objPed.dtItensPedido.Rows[i]["ItPQtde"];
                            dt.Rows[i]["Vlr. Unit."] = objPed.dtItensPedido.Rows[i]["ItPrecoComp"];
                            dt.Rows[i]["Vlr. Desconto"] = objPed.dtItensPedido.Rows[i]["ItPDesconto"];
                            dt.Rows[i]["Vlr. Total"] = objPed.dtItensPedido.Rows[i]["ItPTotal"];
                            dt.Rows[i]["Reorder"] = objPed.dtItensPedido.Rows[i]["ItPReorder"];
                            dt.Rows[i]["Tipo Item"] = objPed.dtItensPedido.Rows[i]["ItPOrigem"];
                            dt.Rows[i]["Qtd.Dig."] = objPed.dtItensPedido.Rows[i]["ItPQtdeDig"]; //Qtd.Dig.
                        }
                        gridPedidos.DataSource = dt;
                        gridPedidos.Refresh();
    
asked by anonymous 01.12.2017 / 18:11

1 answer

2

Set the value of the property AllowUserToAddRows to false .

If you are going to do this by dedign mode, look for the property in the properties window when selecting the control.

Or, at runtime, do this

dataGridView.AllowUserToAddRows = false;
    
01.12.2017 / 18:14