找不到类型为“字符串"的公共成员“已选择". [英] Public member 'selected' on type 'String' not found.

查看:222
本文介绍了找不到类型为“字符串"的公共成员“已选择".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将通过窗口框列表框选择的多个选择插入数据库中,但是我无法做到这一点....

I am trying to insert into the database of multiple selections selected through a listbox for window form.but i''m unable to do this....

Dim i As Integer
        For i = 0 To ListBox1.Items.Count - 1
            If Me.ListBox1.Items(i).selected Then
                cmd.Parameters.AddWithValue("@coursename", ListBox1.Items(i).ToString())

            End If
        Next


我收到此错误:找不到类型为字符串"的公共成员"已选定"."


I get this error: "Public member ''selected'' on type ''String'' not found."

推荐答案

ListBox. Items [x]返回实际的项目-先前加载的字符串或类实例.它没有封装它,因此它没有Selected属性,除非原始对象有.即使那样,您也必须先将其转换为适当的类型.

相反,请查看ListBox.SelectedItems属性-它只是所选列表的列表,因此您的循环可以只是该列表上的ForEach.
ListBox.Items[x] returns the actual item - a string, or class instance that you loaded earlier. It does not encapsulate it, so it doesn''t have an Selected property, unless the original object does. And even then you would have to cast it to the appropriate type first.

Instead, look at the ListBox.SelectedItems property - it is a list of just the selected ones, so your loop can just be a ForEach on that.


这篇关于找不到类型为“字符串"的公共成员“已选择".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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