如何使用数据绑定列表框进行“针对每个对象"? [英] How to do a 'For each' with databound listbox?

查看:55
本文介绍了如何使用数据绑定列表框进行“针对每个对象"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,好人...

我有以下例程,该例程与listox完美配合,listox带有手动输入的项目(即(集合)).但是,它不会与包含来自SQL数据库的数据绑定项的列表框一起运行.

I have the below routine which works perfectly with a listox with items entered manually (i.e. (collection)). However, it will not run with a listbox containing databound items from a SQL database.

我该如何通过数据源填充列表框呢?

How would I go about getting this to work with a listbox is populated through a datasource?

非常感谢!

--------------------------------------------------- -----

----------------------------------------------------

对于每个i作为AccessoarerListBox.Items中的字符串

           Dim path As String ="g:\ produktbilder \"; &我

          试试
                             '确定目录是否存在.
                            如果Directory.Exists(path)然后
                    'MsgBox(文件夹已存在")
                   退出子
                            如果结束

                             '尝试创建目录.
                             Dim di As DirectoryInfo = Directory.CreateDirectory(path)
                             'MsgBox(文件夹创建")


          捕获异常
                             Console.WriteLine(进程失败:{0}.",a.ToString())
          结束尝试

      下一个

 For Each i As String In AccessoarerListBox.Items

            Dim path As String = "g:\produktbilder\" & i

            Try
                ' Determine whether the directory exists.
                If Directory.Exists(path) Then
                    'MsgBox("Folder already exists")
                    Exit Sub
                End If

                ' Try to create the directory.
                Dim di As DirectoryInfo = Directory.CreateDirectory(path)
                'MsgBox("Folder created")


            Catch a As Exception
                Console.WriteLine("The process failed: {0}.", a.ToString())
            End Try

        Next

--------------------------------------------------- -----

----------------------------------------------------

推荐答案

尝试

对于每个dataRow作为AccessoarerListBox.DataSource中的DataRowView

For Each dataRow As DataRowView In AccessoarerListBox.DataSource

?


这篇关于如何使用数据绑定列表框进行“针对每个对象"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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