Editable ComboBox
-
Monday, January 10, 2011 10:54 AM
Hi,
I have a ComboBox with IsEditable property set to True. I am assigning ItemSource property a List<KeyValuePair<string,string>> type. I have set the DisplayMemberPath to Key. It is displaying the item list right but Now when I select any item it shows same key in the editable text box. I want to display Value field when any item is selected.
How to achieve that?
Regards, Jigs- Changed Type jigs12383 Monday, January 10, 2011 1:11 PM
All Replies
-
Monday, January 10, 2011 1:09 PM
Done with the following code.
<Window x:Class="Test.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <StackPanel> <ComboBox x:Name="cmb" DisplayMemberPath="Key" SelectedValuePath="Value" TextSearch.TextPath="Value" IsEditable="True"> </ComboBox> <Button Content="OK" Click="Button_Click"/> </StackPanel> </Window>
namespace Test { public partial class Window1 : Window { List<KeyValuePair<string,string>> lst = new List<KeyValuePair<string,string>>(); public Window1() { InitializeComponent(); lst.Add(new KeyValuePair<string,string>("A:A","AA")); lst.Add(new KeyValuePair<string,string>("B:B","BB")); lst.Add(new KeyValuePair<string,string>("C:C","CC")); cmb.ItemsSource = lst; } private void Button_Click(object sender, RoutedEventArgs e) { MessageBox.Show(cmb.SelectedValue.ToString()); } } }
Regards, Jigs- Marked As Answer by jigs12383 Monday, January 10, 2011 1:11 PM
-
Wednesday, January 12, 2011 2:11 AMModerator
Hi jigs12383,
Thank you for sharing your solution here, I think it will be very beneficial for others having the similar issue to find the solution.
Best regards,
Sheldon _Xiao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.


