Hi,
Is it possible that each time we select a new item in the autocompletebox, the selected item disappears from the list of auto complete items.
This is to avoid to enter twice the same items.
If this is possible, how to do it?
I put an attachment to show what is my current behaviour. What i would like is that once if have selected tag, it does not appears anymore in the list of choice
FYI, I am using auto completion with unbound mode.
Thanks a lot
5 Answers, 1 is accepted
Thank you for writing.
In order to achieve your goal, you can create a derivative of the RadAutoCompleteBoxListElement and override its SuggestOverride method. This is the place where you can manipulate the Items collection that will be displayed in the popup. Here is the sample code snippet:
public
static
List<
string
> tokens =
new
List<
string
>();
public
RadForm1()
{
InitializeComponent();
}
private
void
RadForm1_Load(
object
sender, EventArgs e)
{
this
.customersTableAdapter.Fill(
this
.nwindDataSet.Customers);
this
.radAutoCompleteBox1.AutoCompleteDataSource =
this
.customersBindingSource;
this
.radAutoCompleteBox1.AutoCompleteDisplayMember =
"ContactName"
;
this
.radAutoCompleteBox1.AutoCompleteValueMember =
"CustomerID"
;
this
.radAutoCompleteBox1.Items.CollectionChanged += Items_CollectionChanged;
}
public
class
CustomRadAutoCompleteBox : RadAutoCompleteBox
{
public
override
string
ThemeClassName
{
get
{
return
typeof
(RadAutoCompleteBox).FullName;
}
}
protected
override
RadTextBoxControlElement CreateTextBoxElement()
{
return
new
CustomRadAutoCompleteBoxElement();
}
}
public
class
CustomRadAutoCompleteBoxElement : RadAutoCompleteBoxElement
{
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(RadAutoCompleteBoxElement);
}
}
protected
override
RadTextBoxListElement CreateListElement()
{
return
new
CustomRadTextBoxListElement();
}
public
class
CustomRadTextBoxListElement : RadAutoCompleteBoxListElement
{
protected
override
void
SuggestOverride(
string
pattern)
{
base
.SuggestOverride(pattern);
if
(pattern !=
string
.Empty && tokens.Count > 0)
{
for
(
int
index = 0; index <=
this
.Items.Count - 1; index++)
{
if
(tokens.Contains(
this
.Items[index].Text))
{
this
.Items[index].Height = 0;
}
else
{
this
.Items[index].Height = 20;
}
}
}
}
}
}
private
void
Items_CollectionChanged(
object
sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e)
{
if
(e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.Add)
{
tokens.Add((e.NewItems[0]
as
RadTokenizedTextItem).Text);
}
else
if
(e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.Remove)
{
tokens.Remove((e.NewItems[0]
as
RadTokenizedTextItem).Text);
}
}
I hope this information helps. Should you have further questions I would be glad to help.
Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify it in a way which suits your requirement best.
Regards,
Dess
Progress Telerik
I have attached my sample project for your reference. When a token is already added it is not shown in the list with suggestion when you start typing.
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Hi Dess,
Thanks for your support. I was able to tackle the problem up to some extend, unfortunately I have encountered some issue. The problem is that if selected a specific value from suggestion in auto complete box i may not be able find the same value after completion of that operation. Is there currently any workarounds for this? Can any one please guide me how to tackle this issue too. Thanks in advance.
If I understand your concern correctly, you type something in the text box and a suggestions pop up is shown. Then you select an item and a token for it is created. However, if you type the same text again, the suggestions in the popup won't display the already tokenized item. This is expected behavior in the custom implementation because it is how the duplicated entries are avoided. If you need some other behavior, could you please specify in details what behavior you are expecting? Thus, we would be able to think about a suitable solution and assist you further.
I would like to note that we already have a feature request for introducing a mode for disabling the selection of already selected items. You can track its progress, subscribe for status changes and add your comments on the following link - https://feedback.telerik.com/winforms/1372559-add-radautocompletebox-mode-disabling-the-selection-of-already-selected-items
There is also a sample project attached the feedback item.
I am looking forward to your reply.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik