上次Nothing说不能在DataGrid中加入其他控件,其实是可以的,只要重写DataGridTableStyle下的DataGridTextBoxColumn就可以加入ComboBox等的控件了,但我实现了以后不能把ComboBox上修改的数据提交到DataGrid的网格上,代码如下:
Dim da As New DataTable
Dim cbb As New ComboBox
Private Function CreaTable() As DataTable
da.Columns.Add("货物代号", GetType(String))
da.Columns.Add("名称/规格", GetType(String))
da.Columns.Add("数量", GetType(Single))
da.Columns.Add("供应商", GetType(String))
da.Columns.Add("采购日期", GetType(DateTime))
da.Columns.Add("交货日期", GetType(DateTime))
Return da
End Function
Private Sub BuyList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ts As New DataGridTableStyle
Dim dgc As New DataGridComboBoxColumn
Dim dgt1 As New DataGridTextBoxColumn
Dim dgt2 As New DataGridTextBoxColumn
Dim dgt3 As New DataGridTextBoxColumn
Dim dgt4 As New DataGridTextBoxColumn
Dim dgt5 As New DataGridTextBoxColumn
da = CreaTable()
DataGrid1.DataSource = da
ts.MappingName = da.TableName
Dim gif As Object = New Object(2) {"sd", "sf", "sa"}
cbb.Items.AddRange(gif)
cbb.Cursor = Cursors.Arrow
cbb.DropDownStyle = ComboBoxStyle.DropDownList
cbb.Dock = DockStyle.Fill
dgc.TextBox.Controls.Add(cbb)