简体   繁体   English

Winforms组合框选择值后更改displaytext

[英]Winforms combobox change displaytext after selecting a value

I have an editable comboxbox bound to a List in a Winform application. 我有一个绑定到Winform应用程序中的列表的可编辑comboxbox。

public class Address
    {
        public string DisplayText { get; set; }
        public string DropDownText { get; set; }
    }

I want to display DropDownText when user expands the combobox, but I want show the DisplayText as Combobox's text after user has selected the dropdown item. 我想在用户展开组合框时显示DropDownText,但是我想在用户选择下拉菜单项后将DisplayText显示为Combobox的文本。

I can do this in WPF by using TextSearch.SetTextPath property. 我可以通过使用TextSearch.SetTextPath属性在WPF中执行此操作。 Is it possible in Winforms? Winforms中可能吗?

Found the answer: 找到了答案:

private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
{
    var value = comboBox1.SelectedValue.ToString();
    BeginInvoke(new MethodInvoker(delegate()
    {
        comboBox1.Text = value;
    }));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM