我正在使用VB.NET v4编写和应用程序。我有2个列表框,使用相同数据源的变体。我希望能够从列表框1中选择并让列表框2设置它的选择以匹配列表框1中的那个。 我找到了怎么做这在MSDN上,但出于某种原因,当我尝试使用
I am using VB.NET v4 to write and app. I have 2 list boxes that use variations of the same data source. I want to be able to select from list box 1 and have list box 2 set it's selection to match the one from list box 1. I have found how to do this on MSDN, but for some reason, when I try to use
ListBox2.FindStringExact(string)VS2012说FindStringExact不是System.Windows.Controls.Listbox的成员。 MSDN说它是System.Windows.Forms的成员,但VS2012不允许我使用
VS2012 says that FindStringExact is not a member of System.Windows.Controls.Listbox. MSDN says it's a member of System.Windows.Forms, but VS2012 won't let me use
Imports System.Windows.Forms,因为它没有显示为可用。
, as it doesn't show as being available.
推荐答案好的,我得到它。 FindStringExact是System.Windows.Forms.ListBox类的一个方法。 但你使用的是WPF。 这两个是有自己的控件集的库,有一些共同点,也有一些差别。 WPF ListBo x显然没有这种方法。 干得好:) 从你的回答我的评论:我不建议混合使用Windows Forms和WPF。 此处 [ ^ ]是MSDN WPF ListBox控件的页面。到目前为止,我不是WPF专家,所以我不会冒险给出正式的解决方案,但是你可以找到用提供的方法实现目标的方法。 Ok, I get it. FindStringExact is a method of System.Windows.Forms.ListBox class. But you are using WPF. These are two libraries that have their own sets of controls, which have some things in common, and some differences also. WPF ListBox does not have this method, apparently. Good work :) From your answer to my comment: I would not recommend to mix the use of Windows Forms and WPF. Here[^] is the MSDN page of the WPF ListBox control. I'm not a WPF specialist, by far, so I would not risk giving a formal solution, but there you may find the way to achieve your goal with provided methods.
请看我的评论这个问题。没有什么需要解释,但我会尝试。 你把一切都搞砸了。不,不仅没有这样的方法,而且你的声明MSDN说它是System.Windows.Forms的成员,但VS2012不会让我使用也与真相无关。这又是你的幻想。事实上,有一些以此名称已知的.NET FCL方法,例如,这两个: msdn.microsoft/en-us/library/system.windows.forms.listbox.findstringexact%28v=vs.110%29.aspx [ ^ ]。 但这些方法与您的WPF代码无关。但是如果你想使用 System.Windows.Forms.ListBox ,请使用它,但不要询问WPF ListBox 。 实际上, System.Windows.Forms 的这两种方法完全冗余。您可以循环遍历列表框项目并找到您想要的任何内容。 但更重要的是要了解类似的功能不适用于WPF。在WPF列表框中,项目不是字符串。 (惊喜?然后阅读MSDN文档。) 在WPF中,它们是任意对象。但是在WPF中,实际的UI元素是基于 System.Object 类型的元素动态创建的,并出现在WPF 可视树中。这是一个非常重要的WPF概念,您无法理解: https:// msdn .microsoft / library / ms753391%28v = vs.100%29.aspx [ ^ ]。 如果需要,可以遍历列表中的所有元素框并在每个上调用函数 System.Object.ToString()来查找字符串,但这是一种蹩脚的方法。强大的方法是将适当的语义敏感数据类型的数据作为列表框项而不是字符串。您可以通过覆盖项类型的 System.Object.ToString()来控制字符串表示。我在过去的答案中解释了它适用于WPF和表格: 更新不同窗口上的列表视图 [ ^ ], wpf无模式对话框和窗口,如何沟通 [ ^ ], 如何以两种形式复制列表框之间的所有项目 [ ^ ], combobox.selectedvalue在winform中显示{} [ ^ ]。 因此,您可以实现搜索:遍历列表框项目在一个循环中,检查每一个以找到你想要的任何匹配。
更多推荐
为什么我不能使用ListBox.FindStringExact?
发布评论