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:

  1. create form , put datagridview, bindingnavigator , bindingsoure ono it
  2. 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.

enter image description here


Comments

Popular posts from this blog

swift - Button on Table View Cell connected to local function -

dns - Dokku server hosts two sites with TLD's, both domains are landing on only one app -

c# - ajax - How to receive data both html and json from server? -