Hello, when my application adds items to the auto complete box pragmatically I turn them red. I wish to hide the X button so the user cannot remove them. Is this possible? I noticed there is a ShowRemoveButton property on the control but that seems like it is for all tokens? Here is some of my code. Thank you for the assistance.
Private Sub AddToken(ByVal ac As RadAutoCompleteBox, ByVal email As String)
Dim result As EmailTokenObject = AllEmails.Find(Function(o) o.Email.ToLower = email.ToLower)If result IsNot Nothing Then
Dim flag = False 'search for pre-existing items to make sure we don't add them double
For Each item As RadTokenizedTextItem In ac.Items
If item.Value.ToString.ToLower = email.ToLower Then
flag = True
End If
Exit For
Next
If flag = False Then
'this has to be called BEFORE we add the item to the textbox
PrePopulatedEmails.Add(result.Email) 'add to the prepopulated emails so we can color it in red and remove the ability to remove the item
'add the item
ac.AppendText(result.Name & ";")
End If
End If
End Sub
Private Sub acWatchlist_TokenValidating(sender As Object, e As TokenValidatingEventArgs) Handles acWatchlist.TokenValidating
If acWatchlist.Text.Contains(e.Text) Then
e.IsValidToken = False
End If
End Sub
Private Sub acWatchlist_TextBlockFormatting(sender As Object, e As TextBlockFormattingEventArgs) Handles acWatchlist.TextBlockFormatting
Dim token As TokenizedTextBlockElement = TryCast(e.TextBlock, TokenizedTextBlockElement)
If token IsNot Nothing AndAlso PrePopulatedEmails.Contains(token.Item.Value, StringComparer.OrdinalIgnoreCase) Then
token.GradientStyle = GradientStyles.Solid
token.BackColor = Color.Red
End If
End Sub
I was able to resolve part of this issue with: token.RemoveButton.Visibility = ElementVisibility.Hidden. However the user can still backspace the item, click and press delete, and right click context menu delete the item. How can I stop this is there an easy way?