Das Control scheint unter bestimmten Bedingungen fehlerhaft zu arbeiten.
Ich empfehle für die Steuerung: 2 Comboboxen und einen Button:
Public Class frmDatagridviewGrouperEditable
Dim WithEvents cboColumns As New ComboBox With _
{.Parent = Me, .Width = 150, .Enabled = False, _
.DropDownStyle = ComboBoxStyle.DropDownList}
Dim WithEvents cboOptions As New ComboBox With _
{.Parent = Me, .Width = 150, .Left = 160, .Enabled = False, _
.DropDownStyle = ComboBoxStyle.DropDownList}
Dim WithEvents btnGrouper As New Button With _
{.Parent = Me, .Width = 100, .Left = 320, .Text = "Gruppieren"}
Dim WithEvents grp As Subro.Controls.DataGridViewGrouper
Dim bs As New BindingSource
Dim dgv As New DataGridView With _
{.Parent = Me, .Top = 50, .Width = 400, .Height = 300, _
.DataSource = bs, .ScrollBars = ScrollBars.Both}
Dim dt As New DataTable
Private Sub frmDatagridviewGrouperEditable_Load(sender As System.Object, _
e As System.EventArgs) Handles MyBase.Load
Me.Size = New Size(430, 400)
Me.MinimumSize = Me.Size
CreateData()
bs.DataSource = dt
SetCombos()
End Sub
Private Sub SetCombos()
With cboOptions.Items
.Add("Expand All")
.Add("Collapse All")
.Add("Sort Ascending")
.Add("Sort Descending")
.Add("Show Row Count")
.Add("Show Group Name")
End With
For i As Integer = 0 To dt.Columns.Count - 1
cboColumns.Items.Add(dt.Columns(i).ColumnName)
Next i
cboColumns.SelectedIndex = 0
End Sub
Private Sub SetOptions()
With grp
Select Case cboOptions.SelectedIndex
Case 0 : .ExpandAll()
Case 1 : .CollapseAll()
Case 2 : .GroupSortOrder = SortOrder.Ascending
Case 3 : .GroupSortOrder = SortOrder.Descending
Case 4 : .Options.ShowCount = Not .Options.ShowCount
Case 5 : .Options.ShowGroupName = Not .Options.ShowGroupName
End Select
End With
End Sub
Private Sub CreateData()
'Testspalten und -daten
With dt.Columns
.Add("Groups")
.Add("Numbers", GetType(Double))
.Add("Bools", GetType(Boolean))
End With
Dim rndm As New Random
For i As Integer = 0 To 100
Dim r As DataRow = dt.NewRow
If i Mod 5 = 0 Then
r("groups") = DBNull.Value
Else
r("Groups") = "g:" & rndm.Next(1, 5).ToString
End If
r("Numbers") = Math.Round(rndm.NextDouble, 1)
r("Bools") = If(rndm.NextDouble > 0.5, True, False)
dt.Rows.Add(r)
Next i
End Sub
Private Sub btnGrouper_Click(sender As Object, _
e As System.EventArgs) Handles btnGrouper.Click
If grp IsNot Nothing Then
grp.Dispose()
grp = Nothing
Enabler(False)
btnGrouper.Text = "Gruppieren"
Else
Enabler(True)
grp = New Subro.Controls.DataGridViewGrouper(dgv)
grp.SetGroupOn(cboColumns.Text)
btnGrouper.Text = "Editieren"
SetOptions()
End If
End Sub
Private Sub Enabler(ByVal ok As Boolean)
cboColumns.Enabled = ok
cboOptions.Enabled = ok
dgv.AllowUserToAddRows = Not ok
dgv.AllowUserToDeleteRows = Not ok
dgv.ReadOnly = ok
End Sub
Private Sub cboColumns_SelectedIndexChanged(sender As Object, _
e As System.EventArgs) Handles cboColumns.SelectedIndexChanged
If grp IsNot Nothing Then
grp.SetGroupOn(cboColumns.Text)
End If
End Sub
Private Sub grp_DisplayGroup(sender As Object, _
e As Subro.Controls.GroupDisplayEventArgs) Handles grp.DisplayGroup
If e.DisplayValue = String.Empty Then
e.DisplayValue = "<fehlend>"
End If
End Sub
Private Sub cboOptions_SelectedIndexChanged(sender As Object, _
e As System.EventArgs) Handles cboOptions.SelectedIndexChanged
SetOptions()
End Sub
End Class
Beitrag wurde zuletzt am 13.11.17 um 07:59:33 editiert. |