本文介绍了从列表框中获取项目的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望将列表框"的选定项值"设置为字符串.我怎样才能做到这一点.我想要项的值而不是文本.任何愿意帮助的人都会非常感谢.
I want the Selected Items Value of a List box to a string. How can i do that. I want the value of the items not the text. Any one who will help will be most thankfull.
推荐答案我将假设您已将列表框绑定到数据表.如果是这样,我本人就无法使用SelectedValue. 我发现有效的方法是使用以下方法来获取选定的值: I''m going to assume that you have the listbox bound to a datatable. If so, I''ve had trouble with the SelectedValue myself. What I''ve found works is to use the following to get the selected value: Listbox.SelectedItems(X)(Listbox.ValueMember)
只需将"Listbox"替换为控件的名称,将"X"替换为要获取其值的所选项目的索引. 如果一次只允许1个选择,则可以将"X"硬编码为0. 祝你好运!
Just replace "Listbox" with the name of your control, and "X" with the index of the selected item you''re getting the value for. If you''re only allowing 1 selection at a time, then you can hardcode the "X" as 0. Good luck!
如果您有一个字符串,并且想要从中获取值,可以查看此 [ ^ ]并使用convert方法. If you have a string and you want to get the value out of that, you can have a look at this[^] and use the convert method.
我为您提供了一种最简单的方法..!你会喜欢的. . I have a one gud Simplest way for you..!! you will love this. . Dim i As Integer Dim item(ListBox1.SelectedItems.Count - 1) As String For Each item(i) In ListBox1.SelectedItems ListBox2.Items.Add(item(i).ToString()) i += 1 Next
对您有帮助吗?
does it help u?
更多推荐
从列表框中获取项目的价值
发布评论