|
-
Sep 2nd, 2010, 07:37 PM
#1
Thread Starter
Lively Member
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)
-
Sep 2nd, 2010, 07:52 PM
#2
Re: Rows cannot be programmatically added to the DataGridView's rows collection
add a row to your datasource + it'll appear in your dgv
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 2nd, 2010, 08:07 PM
#3
Thread Starter
Lively Member
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
-
Sep 2nd, 2010, 08:18 PM
#4
Re: Rows cannot be programmatically added to the DataGridView's rows collection
can you post the code you use to bind your DataGridView?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 2nd, 2010, 08:21 PM
#5
Thread Starter
Lively Member
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
-
Sep 2nd, 2010, 08:25 PM
#6
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)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 2nd, 2010, 08:42 PM
#7
Thread Starter
Lively Member
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
-
Sep 3rd, 2010, 05:43 AM
#8
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}
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|