Hello Sebastien,
Thank you for writing.
By default,
RadAutoCompleteBox performs searching of items considering only the text. Hence, when you have duplicated names, it is normal that the first one will be selected. In order to achieve the required functionality, you can use the following approach:
public
Form1()
{
InitializeComponent();
DataTable dt =
new
DataTable();
dt.Columns.Add(
"Id"
,
typeof
(
int
));
dt.Columns.Add(
"Name"
,
typeof
(
string
));
dt.Rows.Add(1,
"Smith"
);
dt.Rows.Add(2,
"Smith"
);
dt.Rows.Add(3,
"Smith"
);
dt.Rows.Add(4,
"Brown"
);
this
.radAutoCompleteBox1.AutoCompleteDataSource = dt;
this
.radAutoCompleteBox1.AutoCompleteDisplayMember =
"Name"
;
this
.radAutoCompleteBox1.AutoCompleteValueMember =
"Id"
;
this
.radAutoCompleteBox1.ListElement.Tag = 2;
this
.radAutoCompleteBox1.Text =
"Smith;"
;
}
private
void
radButton1_Click(
object
sender, EventArgs e)
{
Console.WriteLine(
this
.radAutoCompleteBox1.Items.Last().Value);
}
public
class
CustomAutoCompleteBox : RadAutoCompleteBox
{
protected
override
RadTextBoxControlElement CreateTextBoxElement()
{
return
new
CustomAutoCompleteBoxElement();
}
public
override
string
ThemeClassName
{
get
{
return
typeof
(RadAutoCompleteBox).FullName;
}
}
}
public
class
CustomAutoCompleteBoxElement : RadAutoCompleteBoxElement
{
protected
override
RadTextBoxListElement CreateListElement()
{
return
new
CustomTextBoxListElement();
}
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(RadAutoCompleteBoxElement);
}
}
}
public
class
CustomTextBoxListElement : RadTextBoxListElement
{
public
override
RadListDataItem Find(
string
text)
{
RadListDataItem item =
this
.SelectedItem;
if
(item !=
null
&&
this
.IsMatching(item.Text, text))
{
return
item;
}
for
(
int
index = 0; index <
this
.DataLayer.ListSource.Count; index++)
{
item =
this
.DataLayer.ListSource[index];
if
(
this
.IsMatching(item.Text, text) &&
this
.Tag +
""
== item.Value +
""
)
{
return
item;
}
}
return
null
;
}
}
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the
Telerik API Analyzer and share your thoughts.