如何在Visual Studio中为组合框添加值单独保留文本 [英] How Do I Add Value Into A Combobox In Visual Studio Leave Alone The Text

查看:142
本文介绍了如何在Visual Studio中为组合框添加值单独保留文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我希望能够为组合框添加一个值,以便我以后可以存储该字符,例如。 M到我在sql中的表。我不希望全文存储在我的表示例中男性



任何帮助plssss !!!

Hi
I want to be able to add a value to a combobox so that i can later store the character eg. M to my table in sql. i do not want the full text to be stored in my table example Male

any help plssss!!!

推荐答案

检查以下链接。



使用组合框控件



vob.net with combobox with database


这是示例代码。请试试这个。





Here is sample code. please try this.


class MyClass
        {
            public string Data { get; set; }
            public string Value { get; set; }
        }

        private void BindData()
        {
            ComboBox yourComboBox = new ComboBox();

            List<MyClass> obj = new List<MyClass>();
            for (int i = 0; i < 5; i++)
            {
                obj.Add(new MyClass() { Data = "Data" + i, Value = (i * 5).ToString() });
            }

            yourComboBox.DisplayMember = "Data";
            yourComboBox.ValueMember = "Value";
            yourComboBox.DataSource = obj;
        }





工作正常我已经测试过......

如果有任何混淆让我知道。



it is working fine i have tested...
if any confusion let me know.


这篇关于如何在Visual Studio中为组合框添加值单独保留文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆