簡體   English   中英

DevExpress XtraGrid GroupRow,CheckEdit交互的可能性

[英]DevExpress XtraGrid GroupRow, CheckEdit Interactions Possibilities

當前,我正在顯示包含組行的XtraGrid。 我有一個“全選” DevExpress.XtraEditors.CheckEdit控件(這與我在文檔中了解的這種難以捉摸的“全選”復選框控件不同)。 有所不同是有原因的:我希望復選框執行“全選”以外的其他操作(根據DevExpress文檔,它僅提供三種不同的選擇)。

我希望用戶能夠使用CheckEdit控件執行以下兩項操作之一。 [1]如果沒有展開任何“組行”,我想選擇所有“組行”。 [2]如果展開了一個或多個“組行”,我只想選擇展開的行。

目前,我能夠操縱控件僅執行以下兩項操作之一(請參見代碼)。 我的問題是雙重的:這可能嗎? 如果是這樣,我將如何處理?

這是我執行上述兩個“事物”中的第二個的代碼:

'If the CheckEdit control is checked:  

xtraGrid.SelectAll()

Dim rowHandles() As Int32 = xtraGrid.GetSelectedRows()  

If rowHandles.Count > 0 Then
    For Each RowHandle As Int32 In rowHandles
        If xtraGrid.IsGroupRow(RowHandle) Then
            xtraGrid.UnselectRow(RowHandle)
        End If
    Next
End If

如您所見,所有這些實際上只是一種解決方法。 在我的調用.GetSelectedRows()可能還存在比所需更多的開銷。 我只是試圖對行類型進行排序,以保持選擇行或.UnselectRow()

您可以使用GridView.GetRowExpanded方法來檢查是否擴展了特定的組行。 要遍歷可見行,可以使用GridView.RowCount屬性。 要獲取行級別,只需使用GridView.GetRowLevel方法。 另外,您還需要使用GridView.IsNewItemRow方法和GridView.IsFilterRow方法檢查行是新項目行還是過濾器行。 對於所有這些方法,您需要使用GridView.GetVisibleRowHandle方法來獲取Row handle 使用選擇時,最好在代碼外部使用GridView.BeginSelection方法和GridView.EndSelection方法。
更新:如果要在折疊組中選擇隱藏行,則可以使用GridView.GetChildRowCount方法和GridView.GetChildRowHandle方法來獲取所有隱藏行。
這是一些示例代碼,它們一起執行您的兩件事:

Private Sub SomeSub

    If xtraGrid.GroupCount = 0 Then
        xtraGrid.SelectAll()

        Exit Sub
    End If

    xtraGrid.BeginSelection()
    xtraGrid.ClearSelection()

    Dim isExpanded As Boolean = False

    For rowVisibleIndex = 0 To xtraGrid.RowCount - 1
        Dim rowHandle As Integer = xtraGrid.GetVisibleRowHandle(rowVisibleIndex)

        If xtraGrid.IsNewItemRow(rowHandle) Then
            Continue For
        End If

        Dim level As Integer = xtraGrid.GetRowLevel(rowHandle)

        If level = 0 Then
            If Not isExpanded Then
                isExpanded = xtraGrid.GetRowExpanded(rowHandle)

                If isExpanded Then
                    xtraGrid.ClearSelection()
                Else
                    xtraGrid.SelectRow(rowHandle)
                End If
            End If
        Else
            xtraGrid.SelectRow(rowHandle)

            'Update: select hidden rows
            If xtraGrid.IsGroupRow(rowHandle) And Not xtraGrid.GetRowExpanded(rowHandle) Then
                SelectRowHierarchy(rowHandle)
            End If
        End If
    Next

    xtraGrid.EndSelection()

End Sub

Private Sub SelectRowHierarchy(rowHandle As Integer)

    Dim childCount As Integer = xtraGrid.GetChildRowCount(rowHandle)

    For childIndex As Integer = 0 To childCount - 1

        Dim childRowHandle As Integer = xtraGrid.GetChildRowHandle(rowHandle, childIndex)

        xtraGrid.SelectRow(childRowHandle)

        If xtraGrid.IsGroupRow(childRowHandle) Then
            SelectRowHierarchy(childRowHandle)
        End If
    Next

End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM