Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试过
if( ListBox.SelectedItem.ToString().Equals("test") { //do something }
和
if( ListBox.SelectedValue.ToString().Equals("test") { //do something }
他们都没有将选定的值或项目放入字符串
如果那是您的代码的实际外观,则存在错误。您应该在 if 语句的末尾添加一个大括号。
如果不是,我在那里看不到任何错误。但请注意,如果您使用 SelectedItem.toString()。那没有给你价值。这将返回对象值。例如,它将为您提供类似“System.Data.DataRowView”的内容。所以这个条件永远不会实现。
这就是我从您的代码中看到的全部内容。