我的组合框返回不正确的文本值

本文关键字:文本 不正确 返回 组合 我的 | 更新日期: 2023-09-27 18:25:04

 public void DD_Location()
    {
        var ctx = new LCCDB_EF();
        var query = ctx.tbl_Location;
        CB_Location.DataContext = query.ToList();
    }
    private void CB_Location_DropDownClosed(object sender, EventArgs e)
    {           
       textbox_test.Text =CB_Location.Text;
    }

文本框中的输出

System.Data.Entity.DynamicProxies.Location_5E43C6C196972BF0754973E48C9C941092D86818CD94005E9A759B70BF6E48E6

我的组合框返回不正确的文本值

试试这个

if(null != CB_Location.SelectedItem)
    textbox_test.Text = CB_Location.SelectedItem.ToString();

如果没有看到你的 XAML,我无法确定,但你确定你已正确绑定列表吗?尝试将组合框的 Items 属性设置为列表,而不是数据上下文。根据类型以及要将文本绑定到的内容,可能还需要根据需要设置 DisplayMemberPath 属性。