如何检索ListBox的ValueMember属性的值 [英] How to retrieve ValueMember property's value of ListBox

查看:69
本文介绍了如何检索ListBox的ValueMember属性的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们同时具有一个列表框的DisplayMember和ValueMember属性,该列表框填充了表的2个字段.在选择列表框中的任何元素时,我们要获取ValueMember属性的值以从表中检索关联的记录.

为此,我们使用了ListBox1.SelectedValue,它返回"System.Data.DataRowView".

We have both DisplayMember and ValueMember properties of a listbox filled with 2 field of a table. On selecting any element in listbox, we want to get ValueMember property''s value to retrieve associated record from the table.

We used ListBox1.SelectedValue for this purpose which returns "System.Data.DataRowView".

listBox2.DataSource = MainDataSet.Tables["Members"];
                listBox2.DisplayMember = "MemberName";
                listBox2.ValueMember = "MemCode";
                MessageBox.Show(listBox2.SelectedValue.ToString());

推荐答案

您将需要创建自己的类以获取SelectedValue.
请注意如何在此USState 类. 100%29.aspx> msdn示例 [
You will need to create your own class to get the SelectedValue.
Notice how the listbox datasource is set to the USState class in this msdn example[^].


这篇关于如何检索ListBox的ValueMember属性的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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