This is a migrated thread and some comments may be shown as answers.

Selected Item content does not reflect the multiple-field-display done in VisualListItemFormatting

2 Answers 20 Views
ListControl
This is a migrated thread and some comments may be shown as answers.
TravisTr
Top achievements
Rank 1
TravisTr asked on 25 Jul 2014, 12:34 AM
Hello,

I've got a winform rad dropdrown list and all the dropdown items' content appear as expected when I combined 2 data-fields following the instruction in this thread:
http://www.telerik.com/forums/multiple-field-displaymember

Specifically, mine case is:
args.VisualItem.Text = row["LastName"] + ", " + row["FirstName"];  

So far so good.

However I think I still have to set a field to my rdd's MemberDisplay, that is:
               
               
rddlPaList.<strong>DisplayMember </strong>= dsResultPa.Tables[0].Columns[2].ToString(); //string - LastName  (1)<br>               rddlPaList.<strong>ValueMember</strong> = dsResultPa.Tables[0].Columns[3].ToString();  // (interger value - ID) (2)


If I don't have the DisplayMember explicitly set as done in line (1) - in other words, if I remove line (1) >> as the rdd loads, the ID shown up for the selected item, i.e. 142, because of what's being done in (2) - I need (2) to happen, so I must keep that line.

But if I have both lines of codes, then the selected item get the Last Name displayed. I want it to display Last Name, First Name as well.

How can I achieve that? 

Again, although all the items in the dropdown do get rendered in the format I implemented in the VisualListItemFormatting event handling codes, which is LastName, FirstName,  the current item in "the box" has only Last Name displayed and it's getting a bit frustrated. What am I missing? Please help!!!








System.Data.DataRowView



2 Answers, 1 is accepted

Sort by
0
TravisTr
Top achievements
Rank 1
answered on 25 Jul 2014, 12:39 AM
Hello,

I've got a winform rad dropdrown list and all the dropdown items' content appear as expected when I combined 2 data-fields following the instruction in this thread:
http://www.telerik.com/forums/multiple-field-displaymember

Specifically, mine case is:
args.VisualItem.Text = row["LastName"] + ", " + row["FirstName"];  
So far so good.

However I think I still have to set a field to my rdd's MemberDisplay, that is:
               
rddlPaList.DisplayMember= dsResultPa.Tables[0].Columns[2].ToString(); //string - LastName  (1)<br>                                 rddlPaList.ValueMember = dsResultPa.Tables[0].Columns[3].ToString();  // (interger value - ID) (2)

If I don't have the DisplayMember explicitly set as done in line (1) - in other words, if I remove line (1) >> as the rdd loads, the ID shown up for the selected item, i.e. 142, because of what's being done in (2) - I need (2) to happen, so I must keep that line.

But if I have both lines of codes, then the selected item get the Last Name displayed. I want it to display Last Name, First Name as well.

How can I achieve that? 

Again, although all the items in the dropdown do get rendered in the format I implemented in the VisualListItemFormatting event handling codes, which is LastName, FirstName,  the current item in "the box" has only Last Name displayed and it's getting a bit frustrated. What am I missing? Please help!!!

(reposted, please keep this one)











0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 29 Jul 2014, 02:14 PM
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.
 
Tags
ListControl
Asked by
TravisTr
Top achievements
Rank 1
Answers by
TravisTr
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or