简体   繁体   English

从选定的combox获取价值并将其放在文本框c#中

[英]Get value from selected combox and put it on textbox c#

Mabuhay! 马部海!

Hi! 嗨! I search this code here but unfortunately didnt get what I am looking for. 我在这里搜索此代码,但不幸的是没有得到我想要的东西。 Any help on this? 有什么帮助吗?

I got this form and have a combo box which i uses dataset so I can get the value of description on this table. 我得到了这个表格,并有一个组合框,该框使用数据集,因此我可以获取此表上的描述值。 And I have a textbox after that but I wanted to get the value of labor cost based on what I selected on combo box. 之后,我有一个文本框,但我想根据我在组合框中选择的内容来获得人工成本的价值。

heres for my combobox 这是我的组合框

 private void Form1_Load(object sender, EventArgs e)
 {
     // TODO: This line of code loads data into the '_10daliriPayrollDataSet.Description' table. You can move, or remove it, as needed.
     this.descriptionTableAdapter.Fill(this._10daliriPayrollDataSet.Description);
 }

for my laborcost.Text value 为了我的人工成本

private void description_SelectedIndexChanged(object sender, EventArgs e)
{
    laborcost.Text = description.SelectedItem.ToString();
}

I got this error; 我收到了这个错误;

System.Data.DataRowView System.Data.DataRowView

Any help on this? 有什么帮助吗?

Thanks, Chris 谢谢克里斯

try 尝试

description.SelectedItem.Text this will do description.SelectedItem.Text这将做

尝试这个,

description.SelectedValue.ToString();

The correct way of retrieving the item text is the GetItemText method. 检索项目文本的正确方法是GetItemText方法。

It works for any item, including the selected one. 它适用于任何项目,包括选定的项目。 The later can be retrieved from the SelectedItem property. 后者可以从SelectedItem属性中检索。

In your case 就你而言

laborcost.Text = description.GetItemText(description.SelectedItem);

Please note that SelectedText and SelectedValue properties (suggested by some commenters) have different semantics and cannot be used for this purpose. 请注意, SelectedTextSelectedValue属性(由某些评论者建议)具有不同的语义,不能用于此目的。

You need to define DataValue member and Text Member field on your combobox. 您需要在组合框上定义DataValue成员和Text Member字段。 Its binding with DataRowView. 它与DataRowView绑定。

So just add two line after this.descriptionTableAdapter.Fill(this._10daliriPayrollDataSet.Description); 因此,只需在this.descriptionTableAdapter.Fill(this._10daliriPayrollDataSet.Description);之后添加两行;

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

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