求助
上次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)
dgt1.HeaderText = da.Columns(0).ColumnName
dgt1.MappingName = da.Columns(0).ColumnName
ts.GridColumnStyles.Add(dgt1)
DataGrid1.TableStyles.Add(ts)
dgt2.HeaderText = da.Columns(1).ColumnName
dgt2.MappingName = da.Columns(1).ColumnName
ts.GridColumnStyles.Add(dgt2)
DataGrid1.TableStyles.Add(ts)
dgt3.HeaderText = da.Columns(2).ColumnName
dgt3.MappingName = da.Columns(2).ColumnName
ts.GridColumnStyles.Add(dgt3)
DataGrid1.TableStyles.Add(ts)
dgc.HeaderText = da.Columns(3).ColumnName
dgc.MappingName = da.Columns(3).ColumnName
ts.GridColumnStyles.Add(dgc)
DataGrid1.TableStyles.Add(ts)
dgt4.HeaderText = da.Columns(4).ColumnName
dgt4.MappingName = da.Columns(4).ColumnName
ts.GridColumnStyles.Add(dgt4)
DataGrid1.TableStyles.Add(ts)
dgt5.HeaderText = da.Columns(5).ColumnName
dgt5.MappingName = da.Columns(5).ColumnName
ts.GridColumnStyles.Add(dgt5)
DataGrid1.TableStyles.Add(ts)
End Sub
Public Class DataGridComboBoxColumn
Inherits DataGridTextBoxColumn
End Class
求助各位帮我想个办法。