Hello Travis,
Thank you for writing.
The
VisualListItemFormatting event affects only the visual items in the drop down. The displayed text in the editable part of the
RadDropDownList is in correspondence with the
DisplayMember properly, which is desired behavior. However, you can subscribe to the
SelectedIndexChanged event and modify the DropDownListElement.
EditableElement.
Text property according to your requirement. Note that the Text property is synchronized with the
SelectedIndex and setting invalid text will clear the selection (e.Position), which should be cancelled:
public
Form1()
{
InitializeComponent();
List<Customer> customers =
new
List<Customer>();
for
(
int
i = 0; i < 10; i++)
{
customers.Add(
new
Customer(i,
"Last"
+ i,
"First"
+ i));
}
this
.radDropDownList1.VisualListItemFormatting += radDropDownList1_VisualListItemFormatting;
this
.radDropDownList1.SelectedIndexChanged += radDropDownList1_SelectedIndexChanged;
this
.radDropDownList1.SelectedIndexChanging += radDropDownList1_SelectedIndexChanging;
this
.radDropDownList1.DisplayMember =
"LastName"
;
this
.radDropDownList1.ValueMember =
"FirstName"
;
this
.radDropDownList1.DataSource = customers;
}
private
void
radDropDownList1_SelectedIndexChanging(
object
sender, PositionChangingCancelEventArgs e)
{
e.Cancel = e.Position == -1;
}
private
void
radDropDownList1_SelectedIndexChanged(
object
sender, PositionChangedEventArgs e)
{
if
(e.Position > -1)
{
Customer customer =
this
.radDropDownList1.Items[e.Position].DataBoundItem
as
Customer;
this
.radDropDownList1.DropDownListElement.EditableElement.Text = customer.LastName +
" "
+ customer.FirstName;
}
}
private
void
radDropDownList1_VisualListItemFormatting(
object
sender, VisualItemFormattingEventArgs args)
{
Customer customer = args.VisualItem.Data.DataBoundItem
as
Customer;
args.VisualItem.Text = customer.LastName +
" "
+ customer.FirstName;
}
public
class
Customer
{
public
int
Id {
get
;
set
; }
public
string
LastName {
get
;
set
; }
public
string
FirstName {
get
;
set
; }
public
Customer(
int
id,
string
lastName,
string
firstName)
{
this
.Id = id;
this
.LastName = lastName;
this
.FirstName = firstName;
}
}
I hope this information helps. Should you have further questions, I would be glad to help.
Regards,
Desislava
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time.
Watch the videos and start improving your app based on facts, not hunches.