VB.NET DataGridView常用界面属性设置

VB.NET DataGridView常用界面属性设置

With DataGridView1
    .AllowUserToAddRows = False             '用户添加新行
    .AllowUserToDeleteRows = False          '用户删除行数据
    .AllowUserToResizeRows = False          '用户调整行高
    .AllowUserToResizeColumns = False       '用户调整列宽
    .MultiSelect = True         '用户多选
    .ReadOnly = True            '整体内容只读
    .SelectionMode = DataGridViewSelectionMode.FullRowSelect    '用户选择模式(整行)
    .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter                 '所有单元格内容居中
    .RowHeadersVisible = False              '显示行表头
    .RowHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter       '行表头文字居中
    .ColumnHeadersVisible = False           '显示列表头
    .ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter    '列表头文字居中
    '设置列标题不换行
    .ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False
    .ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing ' OR DisableResizing 
    .ColumnHeadersHeight = 26
    '设置行高
    .RowTemplate.MinimumHeight = 30    '设置最小行高
    .RowTemplate.Height = 28           '设置行高


    '取消用户点击列表头排序功能
    For i As Integer = 0 To .Columns.Count - 1
        .Columns(i).SortMode = DataGridViewColumnSortMode.NotSortable
    Next

    '修改列表头背景色
    .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
    .EnableHeadersVisualStyles = False
    .ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(64, 64, 64)

    '设置自动换行
    .DefaultCellStyle.WrapMode = DataGridViewTriState.True
    '设置自动调整高度
    .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
    '修改字体字号及样式
    .Rows(l).DefaultCellStyle.Font = New Font("雅文细黑", 10.0F, FontStyle.Bold)
    '取消列标题点击排序
     For i As Integer = 0 To .Columns.Count - 1
        .Columns(i).SortMode = DataGridViewColumnSortMode.NotSortable
     Next

    '调整行高
    .RowTemplate.Height = 35
End With 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值