Android Question Multiple Cell Selection

RishiKumar2210

Active Member
Hello Guys, I have a problem

If I select multiple rows I need selected row's column values(Name column) in a single variable as string type. Is this possible?

Screenshot_2023-11-24-13-27-03-19_fa73a06bde12172f909256a835e3ae64.jpg
 
Solution
It working But I need two names like this("'name1','name2'") single name inside single quote and two names inside double quotes
Here is the new code taking care of your single and double quotes. You did not ask for the quotes in your first post. Did you know that. . At any rate here is the desired new code:
Code: Copy
Sub btnLog_Click
    Dim j As Int
    If XSelections.IsSelected = False Then
        Log("Nothing is selected")
    Else
        Dim sb As StringBuilder
        sb.Initialize
        sb.Append("'")
        For Each rowid As Long In XSelections.SelectedLines.Keys
            Dim row As Map=B4XTable1.GetRow(rowid)
            sb.Append(row.Get("Name")).Append("','")
            j=j+1
        Next
        Dim s As...
If I select multiple rows I need selected row's column values(Name column) in a single variable as string type. Is this possible?
Code: Copy
If XSelections.IsSelected = False Then
        Log("Nothing is selected")
    Else
        Dim sb As StringBuilder
        sb.Initialize
        For Each rowid As Long In XSelections.SelectedLines.Keys
            Dim row As Map=B4XTable1.GetRow(rowid)
            sb.Append(row.Get("Name")).Append("  ") 
        Next
        Log(sb.ToString) 'will display: Name1  Name2    as one string
    End If
Your screenshot is huge, but your explanation should be more clear. I hope I understood what you wanted.
 
Upvote 1
Code: Copy
If XSelections.IsSelected = False Then
        Log("Nothing is selected")
    Else
        Dim sb As StringBuilder
        sb.Initialize
        For Each rowid As Long In XSelections.SelectedLines.Keys
            Dim row As Map=B4XTable1.GetRow(rowid)
            sb.Append(row.Get("Name")).Append("  ")
        Next
        Log(sb.ToString) 'will display: Name1  Name2    as one string
    End If
Your screenshot is huge, but your explanation should be more clear. I hope I understood what you wanted.
Thanks for ur reply @Mahares. Sure I will try this
 
Upvote 0
Code: Copy
If XSelections.IsSelected = False Then
        Log("Nothing is selected")
    Else
        Dim sb As StringBuilder
        sb.Initialize
        For Each rowid As Long In XSelections.SelectedLines.Keys
            Dim row As Map=B4XTable1.GetRow(rowid)
            sb.Append(row.Get("Name")).Append("  ")
        Next
        Log(sb.ToString) 'will display: Name1  Name2    as one string
    End If
Your screenshot is huge, but your explanation should be more clear. I hope I understood what you wanted.
Thanks @Mahares It working But I need two names like this("'name1','name2'") single names inside single quote and two names inside double quotes.
 
Upvote 0
Code: Copy
If XSelections.IsSelected = False Then
        Log("Nothing is selected")
    Else
        Dim sb As StringBuilder
        sb.Initialize
        For Each rowid As Long In XSelections.SelectedLines.Keys
            Dim row As Map=B4XTable1.GetRow(rowid)
            sb.Append(row.Get("Name")).Append("  ")
        Next
        Log(sb.ToString) 'will display: Name1  Name2    as one string
    End If
Your screenshot is huge, but your explanation should be more clear. I hope I understood what you wanted.
Thanks @Mahares It working But I need two names like this("'name1','name2'") single name inside single quote and two names inside double quotes.
 
Upvote 0
It working But I need two names like this("'name1','name2'") single name inside single quote and two names inside double quotes
Here is the new code taking care of your single and double quotes. You did not ask for the quotes in your first post. Did you know that. . At any rate here is the desired new code:
Code: Copy
Sub btnLog_Click
    Dim j As Int
    If XSelections.IsSelected = False Then
        Log("Nothing is selected")
    Else
        Dim sb As StringBuilder
        sb.Initialize
        sb.Append("'")
        For Each rowid As Long In XSelections.SelectedLines.Keys
            Dim row As Map=B4XTable1.GetRow(rowid)
            sb.Append(row.Get("Name")).Append("','")
            j=j+1
        Next
        Dim s As String = (sb.ToString)
        s= s.SubString2(0, s.LastIndexOf(",'"))   'remove the last 2 characters
        s=$"${QUOTE}${s}${QUOTE}"$   'add double quote
        Log(s)      'will display: "'Name1','Name2'""    as one string        
    End If
End Sub
 
Upvote 1
Solution
Here is the new code taking care of your single and double quotes. You did not ask for the quotes in your first post. Did you know that. . At any rate here is the desired new code:
Code: Copy
Sub btnLog_Click
    Dim j As Int
    If XSelections.IsSelected = False Then
        Log("Nothing is selected")
    Else
        Dim sb As StringBuilder
        sb.Initialize
        sb.Append("'")
        For Each rowid As Long In XSelections.SelectedLines.Keys
            Dim row As Map=B4XTable1.GetRow(rowid)
            sb.Append(row.Get("Name")).Append("','")
            j=j+1
        Next
        Dim s As String = (sb.ToString)
        s= s.SubString2(0, s.LastIndexOf(",'"))   'remove the last 2 characters
        s=$"${QUOTE}${s}${QUOTE}"$   'add double quote
        Log(s)      'will display: "'Name1','Name2'""    as one string       
    End If
End Sub
Thanks @Mahares . It worked.
 
Upvote 0
Back
Top