如何获取所选列表框项的ValueMember [英] How to get the ValueMember of a selected listbox item

查看:62
本文介绍了如何获取所选列表框项的ValueMember的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有程序员,



我尝试过多次获得列表框中所选项目的ValueMember,但它给出了从类型转换的错误在列表框中选择项目时,DataRowView键入String无效。



之前是否有人在VB项目中完成此操作?

Dear all programmers,

I tried in many ways to have the ValueMember of a selected item in listbox, but it gives me the error of "Conversion from type "DataRowView" to type "String" is not valid" while selecting an item in listbox.

Has anyone done this before in a VB Project ?

推荐答案

列表框中的所选项目称为SelectedItem - 它是列表框中具有对象类型的属性。

现在您只需要解析myListbox.SelectedItem到它真正的类型 - 例如一个字符串......
The selected Item from a Listbox is called SelectedItem - it's a Property from the Listbox with the Type 'Object'.
Now you only have to parse the myListbox.SelectedItem to the type it's really is - for example a string ...


我通过尝试在列表框中填充数据的许多方法和方法得到了解决方案。



这样的事情:



I got the solution by trying many ways and methods of filling the data in listbox.

Something like this:

if dt.rows.count >0 then
   with Listbox
   .DisplayMember = "Name"
   .ValueMember = "ID"
   .Datasource= dt
   end with
end if

Listbox_selectedindexchanged

msgbox(Listbox.SelectedValue.ToString)







感谢您的评论。




Thanks for your comments.


这篇关于如何获取所选列表框项的ValueMember的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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