0
votes

I have created 4 datagridview columns in design mode, and I have bounded a datatable to datagridview's datasource, and its generates autocolumns (4 Columns)in gridview.

My doubt is If I create 4 datagrid columns in design mode, How can I place the values of bounded columns to default columns (created in design mode).

See the screenshot, first four columns are created in designmode, other 3 columns autogenerated, But here I dont know how can I correctly place the cells.

enter image description here

This is my first doubt, second is,

Is it possible to add a new row to the same datagridview (from 4 textbox values) ? if yes, How ?

I appreciate your help on this doubts

1

1 Answers

0
votes
  1. You need to bind predefined columns to the columns of the datasource.
    Set DataPropertyName property of DataGridViewColumns to the name of the column in the datasource
Me.DataGridViewColumnOrderDetID.DataPropertyName = "ORDER_DET_ID"
Me.DataGridViewColumnOrderDetItem.DataPropertyName = "ORDER_DET_ITEM"
' etc.

This can be done in the designer too.

And set DataGridView.AutoGeneratedColumns = false.

  1. Create and add new row to the datatable based on the values of textboxes
Dim newRow As DataRow = yourdatatable.NewRow()
With newRow
    .SetField(Of Int32)("ORDER_DET_ID", Int32.Parse(Me.TextBoxOrderDetID.Text))
    .SetField(Of String)("ORDER_DET_ITEM", Me.TextBoxOrderDetItem.Text)
    ' etc.
End If
yourdatatable.Rows.Addf(newRow)