User Tools

Site Tools


k17:k17.5:k17.5.1:start

17.5.1 ColumnView Project 1

In addition to using properties of the ColumnView control, the project demonstrates the sorting of the data and especially the use of the various Move() methods.

B1

Figure 17.5.1.1: Program window - sorting by last name switched on

You can create new (random) data (12 elements) at any time. It is advantageous if you see an element as a row in a ColumnView.

Public Sub btnNewData_Click()
 
  covData.Clear() ' Delete content of the ColumnView. Does not apply to the optional header line!
  SetData(12) ' 12 Inserting new elements with random data
 
' Marking of the first element - if at least one exists
  If Not covData.MoveFirst() Then covData.Key = covData.Item.Key
  txbCurrentKey.Text = covData.Item.Key
 
End
 
Private Sub SetData(iCount As Integer)
 
  Dim i As Integer
 
  Dim aFirstNames As String[] = ["Hans", "Maria", ..., "Robert", "Stefan", "Emma", "Yvonne", "Claus"]
  Dim aSurNames As String[] = ["Meyer", "Lehmann", ..., "Müller", "Grahn", "Kaiser", "Vogt", "Zechlin"]
  Dim aPictures As String[] = ["led_green16.png", "led_red16.png", "led_blue16.png"]
 
  For i = 1 To iCount 
    covData.Add(Str(i), Str(i), Picture[aPictures[Rand(0, aPictures.Max)]])		' 1. Spalte + Bild
    covData[Str(i)][1] = aFirstNames[Rand(0, aFirstNames.Max)]				' 2. Spalte
    covData[Str(i)][2] = aSurNames[Rand(0, aSurNames.Max)]					' 3. Spalte
    covData[Str(i)][3] = Format$(Date(CFloat(Now() - Rnd(7000, 8200))), "dd.mm.yyyy")	' 4. Spalte
  Next
 
End

The data can also be sorted out (→ CheckBox), whereby the data are sorted first after the 3rd column 'Last name'. Afterwards, all other columns can be sorted as well.

Public Sub ckboxSorting_MouseDown()
 
  txbCurrentKey.Text = covData.Item.Key
 
  If ckboxSorting.Value = True Then
     covData.Sorted = False
  Else
     covData.Sorted = True            ' It's to be sorted!
     covData.Columns.Ascending = True ' A → Z
     covData.Columns.Sort = 2         ' Sort by last name
  Endif 
 
End

You can immediately move the internal pointer to the first or last element if there is at least one element - which will be checked. The first or last element is then selected so that you can see the current end position:

Public Sub btnFirst_Click()
 
  If covData.Count > 0 Then ' There is at least one element...
     covData.MoveFirst()
     txbCurrentKey.Text = covData.Item.Key
   ' Select element (ColumnView without Focus: Mark gray)
     covData.Key = covData.Item.Key
  Endif
 
End
 
Public Sub btnLast_Click()
 
  If covData.Count > 0 Then ' There is at least one element...
     covData.MoveLast()
     txbCurrentKey.Text = covData.Item.Key
   ' Select element (ColumnView without Focus: Mark gray)
     covData.Key = covData.Item.Key
  Endif
 
End

From any position you can move the internal pointer step by step to the first or last element:

Public Sub btnUp_Click()
 
  If covData.Count > 0 Then ' There is at least one element...
     If Not covData.MoveAbove() Then 
        txbCurrentKey.Text = covData.Item.Key & " : " & covData.Item[1]
        covData.Key = covData.Item.Key
     Else
        covData.MoveFirst()
     Endif
  Endif
 
End
 
Public Sub btnDown_Click()
 
  If covData.Count > 0 Then ' There is at least one element...
     If Not covData.MoveBelow() Then 
        txbCurrentKey.Text = covData.Item.Key & " : " & covData.Item[1]
        covData.Key = covData.Item.Key
     Else
        covData.MoveLast()
     Endif
  Endif
 
End

From any position you can move the internal pointer from the first to the last element (iteration). This procedure is well suited for reading data from a ColumnView or importing it into a ColumnView. Since the marking is switched off to demonstrate the independence of the internal pointer from the external (marking) pointer, you can recognize the current position during iteration in the text box (key and text of the first column):

Public Sub btnIterationDown_Click()
 
  Dim iLastKey As Integer
 
  If covData.Count > 0 Then ' There is at least one element...
     iLastKey = covData.Key ' Start-Key speichern für ***
  Endif
 
' Set the internal pointer to the topmost element, if possible
  If Not covData.MoveFirst() Then ' There is at least one element...
     Repeat ' ... then iteration of the top element
       txbCurrentKey.Text = covData.Item.Key & " : " & covData.Item[1]
     ' covData.Key = covData.Item.Key ' Mark element disabled
       Wait 0.4
     ' Here are further instructions for processing data from the ColumnView: For example
     ' Print covData.Item[0]; gb.Tab; covData.Item[1]; gb.Tab; covData.Item[2]; gb.Tab; covData.Item[3]
     Until covData.MoveBelow() ' ... until the last element in the ColumnView is reached
     covData.MoveTo(iLastKey) ' ***
  Endif
 
End

To fully specify the source code, you can see how the layout of the ColumnView is defined and start values are set:

Public Sub Form_Open()
 
  FMain.Resizable = False
 
  With covData  
   ' Anzahl der Spalten festlegen
    .Columns.Count = 4
 
    .Header = True ' Kopfzeile anzeigen
   ' Header-Spalten-Namen festlegen
    .Columns[0].Text = ("RGB")
    .Columns[1].Text = ("Vorname")
    .Columns[2].Text = ("Nachname")
    .Columns[3].Text = "Geburtsdatum"
   ' Spalten-Weite festlegen
    .Columns[0].Width = 25
    .Columns[1].Width = 130
    .Columns[2].Width = 130
    .Columns[3].Width = 150
   ' Spalten-Ausrichtung festlegen
    .Columns[0].Alignment = Align.Center
    .Columns[1].Alignment = Align.Normal
    .Columns[2].Alignment = Align.Normal
    .Columns[3].Alignment = Align.Center
 
    .Mode = Select.Single
    .Sorted = False ' Es soll *nicht* sortiert werden!
    .AutoResize = True 
    .Resizable = True
  End With
 
  ckboxSorting.Value = ckboxSorting.False
  SetData(12)
 
' Markierung des 7. Elementes
' If covData.Count > 0 Then ' Es existiert mindestens ein (oberes) Element ...
  If Not covData.MoveFirst() Then ' Es existiert mindestens ein (oberes) Element ...
     If covData.MoveTo(7) = True Then ' Wenn ein Fehler auftrat ...
        covData.MoveBack() ' ... dann zurück zum Ausgangselement
        covData.Key = covData.Item.Key ' Element markieren
     Else
      ' Element markieren (ColumnView hat Focus → Markierung hellgrün (Mint 17.3))
        covData.Key = covData.Item.Key
     Endif
  Endif
 
End
 
Public Sub ckboxSorting_MouseDown()
 
  txbCurrentKey.Text = covData.Item.Key
 
  If ckboxSorting.Value = True Then
     covData.Sorted = False
  Else
     covData.Sorted = True            ' Es soll sortiert werden!
     covData.Columns.Ascending = True ' A → Z
     covData.Columns.Sort = 2         ' Sortieren nach Nachname
  Endif 
 
End
 
Public Sub Form_Close()
  FMain.Close()
End

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k17/k17.5/k17.5.1/start.txt · Last modified: 30.09.2023 by emma

Page Tools