Happy New Year everyone.
I created a hierarchical Custom Listbox with Sections. Sections shouldn’t be select- and clickable (Keydown-Event). It works fine, if the structure is
- Section
- Item (a) // next Selection is b
- Section
- Item (b) // next Selection is a
But if i’ll have 2 or more closed Sections, it doesn’t work.
- Section (1)
- Section (2)
- Item (a) // when use Keydown, Section 4 will be selected and not Item b (that’s what i want)
- Section (3)
- Section (4)
- Section (5)
- Item (b)
I know, it will be maybe a mathematical Thing?! Any Ideas? Below my Source
Thank you all!
[h]Source[/h]
Event Definitions
[code]Sub ExpandRow(row as Integer)
If Me.RowIsFolder(row) Then
Select Case Me.Cell(row, 0)
Case "Parents"
Me.AddItem Array("Dad", "Max Mustermann")
Me.AddItem Array("Mom", "Maria Mustermann")
Case "Children"
Me.AddItem Array("I.", "Clara Mustermann")
Case "Grand-Parents"
Me.AddItem Array("Greg Mustermann")
Me.AddItem Array("Leila Mustermann")
End Select
End If
End Sub
Sub Open
Me.AddSection(“Parents”)
Me.AddSection(“Children”)
Me.AddSection(“Grand-Parents”)
End Sub
Event CellClick(row As Integer, column As Integer, x As Integer, y As Integer) As Boolean
Sub ()
Event KeyDown(Key As String) As Boolean
Sub ()[/code]
Events
[code]Function CellBackgroundPaint(g As Graphics, row As Integer, column As Integer) As Boolean
If row < Me.ListCount Then
If Me.RowIsFolder(row) Then
// Background
g.ForeColor = &cF8F8F800 g.FillRect 0, 0, g.Width, g.Height // Border
g.ForeColor = &cCCCCCC00
If row <> 0 Then
If Not Me.RowIsFolder(row-1) Then
g.DrawLine 0, 0, g.Width, 0 End If
End If
g.DrawLine 0, g.Height-1, g.Width, g.Height-1
Return True
End If
End If
End Function
Function CellClick(row as Integer, column as Integer, x as Integer, y as Integer) As Boolean
Call CellClick(row, column, x, y)
If RowTag(row) = RowType.Section And x > 14 Then Return True // 14 Pixels for the Triangular
End Function
Function CellTextPaint(g As Graphics, row As Integer, column As Integer, x as Integer, y as Integer) As Boolean
Dim Type As RowType = RowTag(row)
If Type = RowType.Section Then
g.Bold = True
g.ForeColor = &c23232300
g.DrawString(Cell(row, column), 0, g.Height - (g.TextHeight/2)) Return True
End If
End Function
Function KeyDown(Key As String) As Boolean
Call KeyDown(Key)
Dim idx As Integer = Me.ListIndex
Dim max As Integer = Me.ListCount
Select Case Asc(Key)
Case 30 // up
Select Case idx - 1
Case 0
If Me.RowIsFolder(0) Then
ListIndex = idx + 1
Else
ListIndex = idx - 1
End If
Case Is > 0
If Me.RowIsFolder(idx - 1) Then
ListIndex = idx - 1
Else
ListIndex = idx
End If
End Select
Case 31 // down
If idx <> Max Then
If idx + 1 < max Then
If Me.RowIsFolder(idx + 1) Then
ListIndex = idx + 1
Else
ListIndex = idx
End If
End If
Else
ListIndex = idx
End If
End Select
End Function[/code]
Methods
[code]Sub AddItem(itemName() As String)
AddRow(itemName)
RowTag(LastIndex) = RowType.Item
End Sub
Sub AddSection(sectionName As String)
AddFolder(sectionName)
RowTag(LastIndex) = RowType.Section
End Sub[/code]
Enumerations
Enum RowType
Section
Item
End Enum