绑定ListBox值 [英] Bound ListBox Values

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

问题描述

我对整个编程事情都很陌生,我的代码语法有点麻烦。


我的代码包含一个绑定列表框,其中显示成员和值成员是两个不同的值。我希望我的程序在列表框中循环,并将列表框中每个项的值成员与固定值进行比较。我的问题是我似乎无法找到获取列表框中项目值的语法。我不能使用DescriptionListBox.SelectedValue。因为未选择该项目。这是我尝试过的一些代码的示例,但它不起作用。


对于count as Integer = 0 To DescriptionListBox.Items.Count - 1


如果DescriptionListBox.Items.Item(count).value = Me.DataSet.Table.Rows(i).Item(1)那么



DescriptionListBox.SetSelected(count,True)


结束如果

下一页


我想我的问题是什么我可以用来代替ListBox.SelectedValue来捕获未选中的绑定列表框项的值吗?

解决方案


我对整个编程工作都很陌生,而且我的代码语法有点麻烦。


我的代码包含一个绑定listbox,其中display member和value成员是两个不同的值。我希望我的程序在列表框中循环,并将列表框中每个项的值成员与固定值进行比较。我的问题是我似乎无法找到获取列表框中项目值的语法。我不能使用DescriptionListBox.SelectedValue。因为未选择该项目。这是我尝试过的一些代码的示例,但它不起作用。


对于count as Integer = 0 To DescriptionListBox.Items.Count - 1


如果DescriptionListBox.Items.Item(count).value = Me.DataSet.Table.Rows(i).Item(1)那么



DescriptionListBox.SetSelected(count,True)


结束如果

下一页


我想我的问题是什么我可以用来代替ListBox.SelectedValue来捕获未选中的绑定列表框项的值吗?



只需使用索引并将其保存到变量中,例如

展开 | 选择 | Wrap | 行号

对不起。我正在使用的版本是VB .NET 2005.我应该在.NET论坛中发布这个版本吗?


当我尝试使用DescriptionListBox.Items.Item(count)时,它为我提供了一个到String错误的转换数据视图,因为它是一个绑定列表框。



只需使用索引并将其保存到变量中,例如

展开 < span class =codeDivider> | 选择 | Wrap | Line数字



对此抱歉。我正在使用的版本是VB .NET 2005.我应该在.NET论坛中发布这个版本吗?


当我尝试使用DescriptionListBox.Items.Item(count)时,它为我提供了一个到String错误的转换数据视图,因为它是一个绑定列表框。



我这里没有vb.net,所以我无法确切地检查出来是什么问题,但是你可以添加方法.ToString ??类似于:

DescriptionListBox.Items.Item(count).ToString


可能有帮助


I''m very new to the whole programming thing and I''m having a little trouble with the syntax of my code.

My code contains a bound listbox where the display member and value member are two different values. I want my program to cycle through the listbox and compare the value member of each item in the list box with a fixed value. My problem is I can''t seem to find the syntax to grab the value of the item in the list box. I can''t use DescriptionListBox.SelectedValue. Because the item is not selected. This is an example of some code I''ve tried, but it is not working.

For count As Integer = 0 To DescriptionListBox.Items.Count - 1

If DescriptionListBox.Items.Item(count).value = Me.DataSet.Table.Rows(i).Item(1) then


DescriptionListBox.SetSelected(count, True)

end if
Next

I guess my question is what can I use in place of ListBox.SelectedValue, to capture the Value of a bound listbox''s item that is not selected?

解决方案

I''m very new to the whole programming thing and I''m having a little trouble with the syntax of my code.

My code contains a bound listbox where the display member and value member are two different values. I want my program to cycle through the listbox and compare the value member of each item in the list box with a fixed value. My problem is I can''t seem to find the syntax to grab the value of the item in the list box. I can''t use DescriptionListBox.SelectedValue. Because the item is not selected. This is an example of some code I''ve tried, but it is not working.

For count As Integer = 0 To DescriptionListBox.Items.Count - 1

If DescriptionListBox.Items.Item(count).value = Me.DataSet.Table.Rows(i).Item(1) then


DescriptionListBox.SetSelected(count, True)

end if
Next

I guess my question is what can I use in place of ListBox.SelectedValue, to capture the Value of a bound listbox''s item that is not selected?

just use the index and save it into a variable e.g

Expand|Select|Wrap|Line Numbers


Sorry about that. The version I''m working with is VB .NET 2005. Should I have posted this in the .NET forum?

When I try using DescriptionListBox.Items.Item(count) it gives me a conversion datarowview to String error, because it is a bound listbox.


just use the index and save it into a variable e.g

Expand|Select|Wrap|Line Numbers


Sorry about that. The version I''m working with is VB .NET 2005. Should I have posted this in the .NET forum?

When I try using DescriptionListBox.Items.Item(count) it gives me a conversion datarowview to String error, because it is a bound listbox.

I dont have vb.net here, so i cant check exactly what''s the problem, but can you add the method .ToString?? something like:
DescriptionListBox.Items.Item(count).ToString

may be it helps


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

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