c# - Populate DataGridView with a default empty row -
i working on windows application (c#). have datagridview
, , able bind data , data displayed, good. want datagridview
display default empty row, if database not have data display. right now, datagridview
empty when there no data available. thank in advance!
when use data-binding datagridview
, bind bindingsource
, value of property allowusertoaddrows
true , datagridview
have empty record @ bottom enable add new record.
you never need add empty record @ bottom of binded datagridview using other ways.
here tiny sample create data list form:
- create form , put datagridview, bindingnavigator , bindingsoure ono it
- doubleclick on form , write code below form_load event:
code:
//example: @".\sqlexpress;initial catalog=yourdatabase;integrated security=true;" var connection = @"your connection string" ; //example: "select * category" var command = "your command"; var tableadapter = new system.data.sqlclient.sqldataadapter(command, connection); var datatable= new datatable(); //get data tableadapter.fill(datatable); //set databindings this.bindingsource1.datasource = datatable; this.datagridview1.datasource = this.bindingsource1; this.bindingnavigator1.bindingsource = this.bindingsource1;
screenshot:
look @ empty record @ bottom of datagridview.
Comments
Post a Comment