How to hide the drop-down arrow of a DataGridViewComboBoxColumn window, such as Visual Studio Properties?

I have a DataGridView where one of the columns is a DataGridViewComboBoxColumn . When the grid fills, this column looks different because a drop-down arrow appears in each cell in the column. I would like to change this so that the drop-down arrow is hidden and displayed only when the row is really selected or when the combo box is selected for editing. The behavior I wanted is similar to the way the property window in Visual Studio handles its values.

+6
c # winforms datagridview
source share
3 answers

In the DataGridViewComboBoxColumn there is a property called DisplayStyle . Set it to Nothing to hide DropDownButton

Additional information about the DataGridViewComboBoxDisplayStyle enumeration is available at this MSDN link.

+9
source share

It took me a while to find this, but above was an answer mixed with several other pages.

Here's how to hide the dropdown from the grid based on the value in another. The ToCheck value must be in the cell before the one that contains the drop-down list that you want to hide.

  Private Sub dgv_CellPainting(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEventArgs) Handles dgv.CellPainting 'Pages Grid needs to be edited when rendering If (e.RowIndex >= 0 AndAlso e.ColumnIndex >= 0) Then Dim valueToCheck = dgv.Rows(e.RowIndex).Cells(2).Value If (valueToCheck <> "True") Then Dim thisCol = DirectCast(dgv.Rows(e.RowIndex).Cells(e.ColumnIndex), DataGridViewComboBoxCell) thisCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing e.PaintBackground(e.ClipBounds, False) e.Handled = True End If End If End Sub 
0
source share

If you set DataGridViewComboBoxColumn.DisplayStyleForCurrentCellOnly = True , then a drop-down menu appears when the cell is the current cell.

0
source share

All Articles