B4J Question Search a tableview

ThRuST

Well-Known Member
Licensed User
Longtime User
I need help to modify this code so that the match is case Independent. For example when searching for form a match will show up even if it was saved as Form or FORM. I have tried ToLowercase but that didn't solve it.


B4X:
Public TmpList As List
Public ListIndex As Int = 0
Public TableView As TableView
TmpList.Initialize

B4X:
Sub SearchDocuments

    If TextboxDocuments.Text = "" Then
        fx.Msgbox(MainForm, "Enter a document name to begin search", "")
        Return
    End If
 
    TmpList.Clear
    ListIndex = 0
    TmpDocSearch = TextboxDocuments.Text
      
    For i = 0 To TableView.Items.size - 1
    
        Dim arr() As String = TableView.Items.Get(i)
    
        If arr(2).Contains(TmpDocSearch) Then
            TmpList.Add(i) 'Just add the index to the row
        End If


          
        If TmpList.Size > 0 Then
            ListIndex = 0
            TableView.SelectedRow = TmpList.Get(ListIndex)    'Select the row from the index
            TableView.ScrollTo (TmpList.Get(ListIndex))

            If TmpList.Size = 1 And TmpList.Size < 2 Then

End If
            
            'UpdateTableview
            
        Else
            ListIndex = -1
            TableView.SelectedRow = -1
            'Display no items found etc.
        
        End If
      
      
    Next
 
    If ListIndex =-1 Then
        fx.Msgbox(MainForm, "No match was found", "")
        Return
    End If
 
End Sub
 
Last edited:

Magma

Expert
Licensed User
Longtime User
I need help to modify this code so that the match is case Independent

You must turn all strings to lowercase or uppercase...

TableView.Items.Get(i) .. but this is object... so first you must make it string...

B4X:
dim a as string
a = arr(2).ToLowerCase

+ You must make ToLowerCase the TmpDocSearch into other string perhaps b...

B4X:
dim b as string
b = tmpdocsearch.tolowercase

So now you can check if a contains b
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Thank you very much, I made it work this way.

B4X:
Sub SearchDocuments
    
    If TextboxDocuments.Text = "" Then
        fx.Msgbox(MainForm, "Enter a document name to begin search", "")
        Return
    End If
    
    Dim a As String
    TmpList.Clear
    ListIndex = 0
    TmpDocSearch = TextboxDocuments.Text.ToLowerCase
          
    For i = 0 To TableView.Items.size - 1
        
        Dim arr() As String = TableView.Items.Get(i)
        
        a = arr(2).ToLowerCase
        
        If a.Contains(TmpDocSearch) Then
            TmpList.Add(i) 'Just add the index to the row
        End If


              
        If TmpList.Size > 0 Then
            ListIndex = 0
            TableView.SelectedRow = TmpList.Get(ListIndex)    'Select the row from the index
            TableView.ScrollTo (TmpList.Get(ListIndex))

            If TmpList.Size = 1 And TmpList.Size < 2 Then

End If
                
            'UpdateTableview
                
        Else
            ListIndex = -1
            TableView.SelectedRow = -1
            'Display no items found etc.
                        
        End If
                    
    Next
    
    If ListIndex =-1 Then
        fx.Msgbox(MainForm, "No match was found", "")
        Return
    End If
    
End Sub
 
Upvote 0
Top