我有一个datagridview1,它通过BindingSource数据绑定到数据集
dim dt as datatable
dim bsData as bindingsource
bsData.DataSource = dt
DataGridView1.DataSource = bsData
我还有来自另一个数据表dt5
的行,我需要添加到datagridview1数据表中
我的代码在datagridview1中创建一个名为Objectives
的新列,但它不会从dt5
任何想法?理解
Dim dt5 As New DataTable
dt5.Load(cmd.ExecuteReader)
Dim mybindingsource As BindingSource = CType(DataGridView1.DataSource, BindingSource)
Dim dtts As DataTable = CType(mybindingsource.DataSource, DataTable)
dtts.Columns.Add("Objectives")
Dim newrow As DataRow
For i = 0 To (dt5.DefaultView.Count - 1)
newrow = dtts.NewRow
newrow.Item("Objectives") = dt5.Rows.Item(i).Item("H1")
dtts.Rows.Add(newrow)
next