Empty DataSets

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is is possible to bind a datagrid to an empty dataset?

Initially, I would like the datagrid to be empty to allow users to insert
new rows.

I have the code to add new rows to the datagrid and to update the DB.
However, I'm not sure how to add empty rows to the dataset, and if it is
possible to bind the datagrid to this.

I am programming in VB.net

Many Thanks
 
Make a DataTable like this:
Dim dtblIsabel As New DataTable
Dim dcolCol As DataColumn

dcolCol = New DataColumn("ID")
dcolCol.DataType = System.Type.GetType("System.Int16")
dtblIsabel.Columns.Add(dcolCol)

dcolCol = New DataColumn("Name")
dcolCol.DataType = System.Type.GetType("System.String")
dtblIsabel.Columns.Add(dcolCol)



Than add your table to your grid liek this:

dbgGrid.DataSource = Nothing

dbgGrid.TableStyles.Clear()

dbgGrid.DataSource = dtblGrid.DefaultView





Maybe a much easier solution is just preparign all the stuff like you use to
do when you bind it to a Table, but put in your select-query a condition
that is always False. Like that you will creat an empty DataGrid...


Hope this is enough,

Pieter
 
Hum, I think this would not scale (though, maybe scalability is not an issue
to consider in this particular case). Consider (and try, I never do it
myself) to create an empty dataset and apply an schema then attach it to the
DataGrid, I think this could work.

Manuel.
 
Back
Top