Adding extra row at the end of datatable when linking to datagridview

I am creating datatable as

        DataTable dtVndDtl = new DataTable();            
        dtVndDtl.Columns.Add("prvn_Id");
        dtVndDtl.Columns.Add("vend_Name");
        dtVndDtl.Columns.Add("vend_Id");
        dtVndDtl.Columns.Add("prvn_Price"); 

      

and adding to datagridview like

        dgvPrdtRws.DataSource = dtVndDtl; 

      

I have set datapropertynames as well .. I am adding rows to datagridview. when i click the save button my data should be saving data from the database. But I get an extra blank line, in the end my lines. Why is this happening. I don't want to add this last line .. so help me

+3


source to share


2 answers


The extra row added at the end will not be added to the database, it is added to the gridview. If you don't want this extra blank row to be displayed, you can set the DataGridView.AllowUserToAddRows property to false. This extra row will not appear in the gridView.



+2


source


I wouldn't bother with why this is happening :). Why don't you just delete the last row manually before adding it to the database?



Another option is to implement a RowCreated event handler and see exactly when that happens so you can do something.

0


source







All Articles