Rows cannot be programmatically added to the DataGridView's rows collection
how to add Rows programmatically to the DataGridView's rows collection when the control is data-bound?
here is my code but i got error as "Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound? "
dtagrdScaleoffinance.Rows.Add(New Object() {Me.txtAccountNumber.Text, Me.txtAccountnumberScaleOfFinance.Text, Me.cmbxCropCode.SelectedIndex, (Me.mskdeffectivedate.Text)
Re: Rows cannot be programmatically added to the DataGridView's rows collection
add a row to your datasource + it'll appear in your dgv
Re: Rows cannot be programmatically added to the DataGridView's rows collection
sorry to ask u again how to add in datasource....
please give me some sample code
Re: Rows cannot be programmatically added to the DataGridView's rows collection
can you post the code you use to bind your DataGridView?
Re: Rows cannot be programmatically added to the DataGridView's rows collection
Private Sub scaleoffinanceview()
Dim dt As New DataTable
dtagrdScaleoffinance.Visible = True
PacsKccDetailsdatagridView.Visible = True
Dim da As OdbcDataAdapter = New OdbcDataAdapter("select * from scaleoffinancedetails_mig where oldaccountnumber = '" & txtAccountNumber.Text & "' ", con)
Dim ds As DataSet = New DataSet
Try
da.Fill(ds, "scaleoffinancedetails_mig")
dt = ds.Tables(0)
dtagrdScaleoffinance.DataSource = dt
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
thi is my code for databinding
Re: Rows cannot be programmatically added to the DataGridView's rows collection
ok. declare dt at form level:
to add a new row:
vb Code:
dim dr as datarow = dt.newrow
dr.itemarray = New Object() {Me.txtAccountNumber.Text, Me.txtAccountnumberScaleOfFinance.Text, Me.cmbxCropCode.SelectedIndex, Me.mskdeffectivedate.Text}
dt.rows.add(dr)
Re: Rows cannot be programmatically added to the DataGridView's rows collection
thank you for ur reply.
i tried your code but i am getting error as input array is longer than number of column in this table
Re: Rows cannot be programmatically added to the DataGridView's rows collection
how many columns does your datatable have?
this is the line you need to change:
vb Code:
dr.itemarray = New Object() {Me.txtAccountNumber.Text, Me.txtAccountnumberScaleOfFinance.Text, Me.cmbxCropCode.SelectedIndex, Me.mskdeffectivedate.Text}