如何将数据从模型绑定到文本框而不是列表框

how to bind data from a model to a text-box instead of a list-box

我通过 dapper 和数据模型从我的数据库中获取数据,然后将该数据绑定到列表框,一切正常,但现在我想将该数据绑定到文本框。以前我只是将数据绑定到一个隐藏的列表框,然后从列表框中获取该数据,但我现在想学习如何正确执行此操作。

          //this is my current workaround.
        textBox1.Text = description.GetItemText(description.SelectedItem);

我也曾尝试将负载清单绑定到文本框,但这不起作用。

        //datamodel prop
        description.DataSource = loadinventory;

        //datamodel full prop
        description.DisplayMember = "ItemDescription";

       textBox1.DataBindings.Clear(); 
       textBox1.DataBindings.Add(new Binding("text", loadinventory, 
       "ItemDescription"));

这很完美。

        textBox1.DataBindings.Clear();
        textBox1.DataBindings.Add(new Binding("text", loadinventory, 
        "ItemDescription"));

我想使用数据模型和 dapper 从我的数据库中提取数据到我的文本框和其他变量。

请尝试

textBox1.DataBindings.Add("text", loadinventory, "ItemDescription");

更多细节https://docs.microsoft.com/de-de/dotnet/api/system.windows.forms.control.databindings?view=netframework-4.8