3

Iam creating a 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 appending to datagridview as

        dgvPrdtRws.DataSource = dtVndDtl; 

I have set the datapropertynames too.. I am adding the rows to datagridview. when I click the save button, my data have to save from datatable to database. But I am getting an extraa empty row la tha last of all my rows. Why does it happening. I dont want to add that last row.. so please help me

4

2 回答 2

2

The extra row that is getting added at the end will not get added in database,it is getting added in gridview. If you don't want that extra empty row to appear then you can set DataGridView.AllowUserToAddRows property to false. That extra row will not appear in gridView.

于 2013-01-31T11:32:47.267 回答
0

I wouldn't really bother with finding out why this happens :). Why don't you just remove the last row manually before adding to database?

Other option is to implement RowCreated event handler and see when exactly this happens so you can do something about it.

于 2013-02-02T19:29:08.393 回答