【问题标题】:How can I hide the drop-down arrow of a DataGridViewComboBoxColumn like Visual Studio Properties window?如何隐藏 DataGridViewComboBoxColumn 的下拉箭头,如 Visual Studio 属性窗口?
【发布时间】:2009-07-10 00:09:02
【问题描述】:

我有一个DataGridView,其中一列是DataGridViewComboBoxColumn。填充网格后,该列看起来不同,因为下拉箭头出现在列中的每个单元格上。我想对此进行更改,以便隐藏下拉箭头,并且仅在实际突出显示该行或选择组合框单元格进行编辑时才显示。我想要的行为就像 Visual Studio 中的 Properties 窗口如何处理它的值。

【问题讨论】:

    标签: c# .net winforms datagridview


    【解决方案1】:

    DataGridViewComboBoxColumn 中,有一个名为DisplayStyle 的属性。将其设置为 Nothing 以隐藏 DropDownButton

    有关DataGridViewComboBoxDisplayStyle 枚举的更多信息,请访问此MSDN link

    【讨论】:

    • 完美!正是我想要的。
    • 设置DataGridViewComboBoxColumn.DisplayStyleForCurrentCellOnly = True 是另一种选择。
    【解决方案2】:

    如果你设置DataGridViewComboBoxColumn.DisplayStyleForCurrentCellOnly = True,那么只有当单元格是当前单元格时才会出现下拉菜单。

    【讨论】:

      【解决方案3】:

      我花了一段时间才找到这个,但上面的答案与其他几页混合在一起。

      这是如何根据不同网格中的值从网格中隐藏下拉菜单。 valueToCheck 必须位于包含您要隐藏的下拉列表的单元格之前的单元格中。

       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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-24
        • 1970-01-01
        • 2021-06-06
        • 2013-11-20
        • 1970-01-01
        • 2022-11-30
        相关资源
        最近更新 更多