包装文本和填充灰色空间

时间:2017-10-26 22:01:49

标签: vb.net datagridview

我正在尝试将文字换成我的" FYI"列,同时保持" .Fill"整个DataGridView的方法。问题是,文本将换行,但DataGridView的宽度以1/4切割而不占用屏幕的其余部分。我做出的任何调整组合似乎要么阻止包装发生,要么扩大" Active"的宽度。从不包含超过3个字符的列(所以我最终会有很多空格):

oCon2 = New SqlConnection
oCon2.ConnectionString = My.Forms.MainForm.GlobalConString
dsFYI = New DataSet
daFYI = New SqlDataAdapter("Select ID, FYI, Active from [Patient_Information].[dbo].[FYI] where [Active] <> 'No' or [Active] is null", oCon)
Dim builder2 As SqlCommandBuilder = New SqlCommandBuilder(daFYI)
builder2.QuotePrefix = "["
builder2.QuoteSuffix = "]"

Try
    daFYI.FillSchema(dsFYI, SchemaType.Source, "FYIGrid")
    daFYI.Fill(dsFYI, "FYIGrid")
    tblFYI = dsFYI.Tables("FYIGrid")
    dataGridView1.DataSource = tblFYI       
Catch ex As Exception
    MsgBox("Something has gone wrong..." & vbNewLine & ex.Message)

Finally
    dataGridView1.Columns("ID").Visible = False
    DataGridView1.Columns("FYI").DefaultCellStyle.WrapMode = DataGridViewTriState.True
End Try

任何帮助都很棒

https://imgur.com/CePhTuF https://imgur.com/mnznDLQ

1 个答案:

答案 0 :(得分:1)

而不是以正常方式填充网格:

Me.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill

在数据绑定后,尝试 使用目标列填充网格。

Private Sub dataGridView1_DataBindingComplete(ByVal sender As Object, _ 
    ByVal e As DataGridViewBindingCompleteEventArgs) _ 
    Handles dataGridView1.DataBindingComplete

    Me.dataGridView1.Columns("FYI").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
    Me.dataGridView1.Columns("FYI").DefaultCellStyle.WrapMode = DataGridViewTriState.[True]
    Me.dataGridView1.Columns("Active").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
    Me.dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells

End Sub

Screenshot of wrapped column filling grid