用代码生成DataGridView,DataSet,并且对DataGridView进行绑定

  • Post author:
  • Post category:其他


Dim column As DataGridViewTextBoxColumn

Me.gdv_detail_list.DataSource = Nothing

Me.gdv_detail_list.Columns.Clear()

column = New DataGridViewTextBoxColumn()

column.HeaderText = “Data Column”

column.DataPropertyName = “data_column”

column.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells

Me.gdv_detail_list.Columns.Add(column)

column = New DataGridViewTextBoxColumn()

column.HeaderText = “Data Value”

column.DataPropertyName = “data_value_before”

column.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells

Me.gdv_detail_list.Columns.Add(column)

Dim tmpDS As New DataSet

tmpDS.Tables.Add(New DataTable())

tmpDS.Tables(0).Columns.Add(“data_column”, GetType(String))

tmpDS.Tables(0).Columns.Add(“data_value_before”, GetType(String))

tmpDS.AcceptChanges()

Dim new_row As DataRow = tmpDS.Tables(0).NewRow

new_row(“data_column”) = “ABC”

new_row(“data_value_before”) = “DEF”

tmpDS.Tables(0).Rows.Add(new_row)

tmpDS.AcceptChanges()

Me.gdv_detail_list.DataSource = tmpDS.Tables(0)



版权声明:本文为wangpeixian原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。