ListBox combine Rows

How can i combine rows, in a listbox, with the the same content, or delete a row with the same content.
The listbox hase over 20 columns.

I would use a dictionary, add the rows as keys (using ListBox.cell(row, -1) ), clear the listbox, add the keys back as rows

Of course you can do it the long-winded way and iterate over all the rows …

Programming! This what you can do in Xojo.

[code]Public Sub DeleteDuplicateRows(Extends lb as Listbox)

Dim dict As New Dictionary

For i As Integer = 0 To lb.ListCount - 1

dict.Value( lb.cell( i, -1 ) ) = 1

// doesn’t matter what you set it to as all we are interested in are the keys

Next

lb.DeleteAllRows

For Each key As Variant In dict.Keys

lb.AddRow 

lb.cell( lb.LastIndex, -1 ) = key 

Next

End Sub[/code]

Note that this only works for text data, not checkboxes etc.

und so funktioniert auch mit CheckBox columns:

[code]Public Sub DeleteDuplicateTextRows(Extends lb as Listbox)

Dim dict As New Dictionary

// store CheckBox state as number in cell

For j As Integer = 0 To lb.ColumnCount - 1

If lb.ColumnType( j ) = Listbox.TypeCheckbox Then 

   For i As Integer = 0 To lb.ListCount - 1

    // store the CheckBox state in the cell 
    If lb.CellState( i, j ) = Checkbox.CheckedStates.Checked Then lb.cell( i, j ) = "1"
    If lb.CellState( i, j ) = Checkbox.CheckedStates.Unchecked Then lb.cell( i, j ) = "0"
    If lb.CellState( i, j ) = Checkbox.CheckedStates.Indeterminate Then lb.cell( i, j ) = "-1"
    
   Next

End If

Next

// NOTE that checked and unchecked rows are now being treated as different
For i As Integer = 0 To lb.ListCount - 1

dict.Value( lb.cell( i, -1 ) ) = 1  

// doesn’t matter what you set it to as all we are interested in are the keys

Next

lb.DeleteAllRows

For Each key As Variant In dict.Keys

lb.AddRow 

lb.cell( lb.LastIndex, -1 ) = key 

Next

For j As Integer = 0 To lb.ColumnCount - 1

If lb.ColumnType( j ) = Listbox.TypeCheckbox Then 
  
  For i As Integer = 0 To lb.ListCount - 1
    
    If lb.Cell( i , j ) = "1" Then lb.CellState( i, j ) = Checkbox.CheckedStates.Checked
    If lb.Cell( i , j ) = "0" Then lb.CellState( i, j ) = Checkbox.CheckedStates.Unchecked
    If lb.Cell( i , j ) = "-1" Then lb.CellState( i, j ) = Checkbox.CheckedStates.Indeterminate
    
    lb.Cell( i , j ) = ""
    
  Next i
  
End If

Next

End Sub
[/code]