禁用单元格边框高亮显示DataGridView

时间:2013-12-04 11:52:30

标签: vb.net winforms datagridview

我正在尝试在选中时禁用单元格周围的边框! (黑色矩形,而不是蓝色背景)。

这可能吗?

argh!

这是我的网格初始化代码(也许会有所帮助):

       With DBGrid
            .RowHeadersVisible = False
            .RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing
            .RowTemplate.Height = internal_RowHeight

            ' Set property values appropriate for read-only display and 
            ' limited interactivity. 
            .AllowUserToAddRows = False
            .AllowUserToDeleteRows = False
            .AllowUserToOrderColumns = False
            .ReadOnly = True
            .SelectionMode = DataGridViewSelectionMode.FullRowSelect
            .AllowUserToResizeColumns = False
            .AllowUserToResizeRows = False
            .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None

            ' Set the row height
            .ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
            .ColumnHeadersHeight = internal_RowHeight
            .ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing


            ' Set the selection background color for all the cells.
            .DefaultCellStyle.BackColor = internal_BackColor
            .DefaultCellStyle.ForeColor = internal_ForeColor
            .DefaultCellStyle.SelectionBackColor = internal_BackColorSel
            .DefaultCellStyle.SelectionForeColor = internal_ForeColorSel


            ' Set RowHeadersDefaultCellStyle.SelectionBackColor so that its default
            ' value won't override DataGridView.DefaultCellStyle.SelectionBackColor.
            .RowHeadersDefaultCellStyle.SelectionBackColor = Color.Empty
            .RowsDefaultCellStyle.BackColor = Color.Empty

            ' Set the row and column header styles.
            .ColumnHeadersDefaultCellStyle.ForeColor = Color.White
            .ColumnHeadersDefaultCellStyle.BackColor = Color.Black

        End With

1 个答案:

答案 0 :(得分:0)

由于您要禁用活动单元格,我假设您只打算使用网格作为选择行而不编辑内容的方法。

在这种情况下,请使用以下设置:

DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
DataGridView1.ReadOnly = True