我用添加Datagridviewcomboboxcolumn列的代码如下:
程序代码:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
mycon.ConnectionString = "Server=.;Database=abcd;User ID=sa;Password=1234"
sqltxt = "select * from Products"
If mycon.State = ConnectionState.Closed Then mycon.Open()
mycmd = New SqlClient.SqlCommand(sqltxt, mycon)
myda = New SqlClient.SqlDataAdapter(mycmd)
myda.Fill(ds, "Categories")
mytab = ds.Tables("Categories")
DataGridView1.DataSource = mytab
Dim abc() As String = {"红", "橙", "黄", "绿", "青", "蓝", "紫"}
Dim List As New DataGridViewComboBoxColumn()
List.Items.AddRange(abc)
List.DisplayIndex = 1
List.HeaderText = "CategoryName"
DataGridView1.Columns.Add(List)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
效果是这样:
如图一:
第二列及第三列没办法合在一起
要怎么写才能合在一起呢?
我要的效果是如图二,图二是我用Combobox做成的,但上下左右翻页后,位置不懂得控制
(另:这怎么贴不了图进来?
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
)