增加行大小取决于DataGridView中的图像

时间:2014-01-23 07:12:22

标签: vb.net winforms datagridview

我有DataGridView这样的

我正在填充我的DataGridView

Dim cd As SqlCommandBuilder = New SqlCommandBuilder(adapter)
adapter = New SqlDataAdapter("select c.cid,c.CompanyName,d.dtId,d.dtName as Department,d.dtPhone as Phone,d.dtEmail as Email,d.empimage from CompanyMaster_tbl c join  DepartmentMaster_tbl d on c.Cid=d.cId order by cid", con.connect)

dt1 = New DataTable
bSource = New BindingSource
adapter.Fill(dt1) 'Filling dt with the information from the DB
bSource.DataSource = dt1
gv.DataSource = bSource
gv.Columns("cid").Visible = False
gv.Columns("dtId").Visible = False
Dim img As New DataGridViewImageColumn
img.HeaderText = "Image"
gv.Columns.Insert(6, img)

For i As Integer = 0 To gv.Rows.Count - 1
    gv.Rows(i).Cells(6).Value = gv.Rows(i).Cells(7).Value
Next
gv.Columns("empimage").Visible = False

如果DataGridView中有ImageColumn图像,我想增加行宽,图像应该在该列中拉伸。我必须在代码中做出哪些更改?

我想发布我的DataGridView图片以便您更好地理解,但我需要至少10个声望来发布图片。

1 个答案:

答案 0 :(得分:0)

使用 gv.AutoSizeRowsModegv.AutoSizeColumnsMode