本文介绍了具有显示和隐藏值的C#中的compobox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我有一个项目,我有一个compobox,在compobox中,我的数据库中有数据表格.
我使用此compobox插入到另一个表中,但是我不希望选择的值是我想要的隐藏值(换句话说,在compobox中,显示的单词是"Name",但我想插入"ID" ;)
谢谢
Hi
I have project I and I have compobox , in the compobox I have data form table in database.
I use this compobox to insert to another table but I don''t want the selected value I want the hidden value ( in other words in the compobox the shown word is " Name " but I want to insert the " ID " )
Thanks
推荐答案
Video video = myComboBox.SelectedItem as Video;
if (video != null)
{
Console.WriteLine("{0}:{1}", video.Id, video.Title);
}
// Set the name as the property to be displayed and the ID as the value to be returned when a row is selected.
// Here these are properties; if we were binding to a database table or query these could be column names.
ComboBox1.DisplayMember = "Name";
ComboBox1.ValueMember = "ID";
// After selection
// this will give you the inner 'hidden' value
textBox1.Text = ComboBox1.SelectedValue.ToString();
// If you also wanted to get the displayed text
// the SelectedItem item property:
// string s = ((USState)ComboBox1.SelectedItem).Name;
这篇关于具有显示和隐藏值的C#中的compobox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!