本文介绍了对于带有列表框的Vb.net中的每个循环,请选中复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 sid = ""
For Each st As String In ListBox1.SelectedItems

            If sid = "" Then
                sid = st
            Else
                sid += st
            End If

  Next
        MessageBox.Show(sid)


它给我一个错误:-从类型"DataRowView"到类型"String"的转换无效.

我如何阅读SelectedItem或SelectedValues或Checkedvalues
我正在使用Visual Studio 2005
请帮助


it is giving me an error :- Conversion from type ''DataRowView'' to type ''String'' is not valid.

how can i read SelectedItem or SelectedValues or Checkedvalues
i am using visual studio 2005
please help

推荐答案

sid = ""
For Each st As String In ListBox1.SelectedItems

            If sid = "" Then
                sid = st
            Else
                sid += st
            End If

  Next
        MessageBox.Show(sid)



问题是,在这种情况下,我已经设置了ListBox的数据源和displaymember属性,因此for和for-each循环不起作用,我不知道为什么,如果有人有任何想法请与我们分享.



problem is i have set the datasource and displaymember property of ListBox in that case for and for-each loop don''t work, i don''t know why, if some one have any idea please share with us.


Dim i As Integer
Dim str As String = ""

For i = 0 To ListBox1.SelectedItems.Count - 1
    str = str & " " & ListBox1.SelectedItems(i).ToString
Next
MessageBox.Show(str)





Dim i As Integer
Dim str As String = ""

For i = 0 To CheckedListBox1.CheckedItems.Count - 1
    str = str & " " & CheckedListBox1.CheckedItems(i).ToString
Next
MessageBox.Show(str)


这篇关于对于带有列表框的Vb.net中的每个循环,请选中复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 06:15