This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello, I use vb.net. I'm following the samples ... for filtering. In the following C# code, you use an anonymous method .... We don't have delegated anonymous methods (to my knowledge) yet in vb ... so, can you provide the vb.net equivalent to the code below? Regards, Douglas Birch private void FilterBox_TextChanged(object sender, TextChangedEventArgs e){ string filterText = FilterBox.Text;#region Defining the filterif (String.IsNullOrEmpty(filterText)){ SetPropertyGridFilter(null);} else{ SetPropertyGridFilter(delegate(object obj){ Node node = ((PropertyGridRow)obj).Node; return node.Name.IndexOf(filterText, StringComparison.CurrentCultureIgnoreCase) >= 0 ||node.HumanName.IndexOf(filterText, StringComparison.CurrentCultureIgnoreCase) >= 0;}); } #endregion } private void SetPropertyGridFilter(Predicate<object> filter){ if (PropertyGrid != null){ #region Applying the filter ICollectionView view = CollectionViewSource.GetDefaultView(PropertyGrid.BindingView);view.Filter = filter; #endregion } } |
|
|
Hello Douglas, If you're using Visual Basic 9 (Visual Studio 2008) then that provides a form of anonymous methods called lambda expressions, with the syntax Dim myFunc = Function (num As Integer) num + 1. See the "Lambda Expressions" topic in MSDN (linked off the "What's New in the Visual Basic Language" topic) for more info. If you're not using VB9, then you'll need to use a named method. In our example there is a slight wrinkle because we also need some state (the filter text) associated with the method. Where can we store state so that it is associated with a method? In an object. So we will translate the C# anonymous method into a rather trivial object with an appropriate method. (In fact this is exactly what the C# compiler does with anonymous methods behind the scenes.) Public Class ByNameFilter Notice how our trivial object "captures" the value of filterText for later use by the Matches method, and how the signature and implementation of the Matches method reflect the C# anonymous method. Now to use this object/method to replace the C# anonymous method: Dim filterText As String = FilterBox.Text The implementation of SetPropertyGridFilter remains the same and should translate easily to VB. Let me know if you need any more information. |
|
|
Thank you for the quick response ... I've implemented the 'named' method for now and it works... I'll place Lamda expressions on my (rather lengthy) list of items to brush up on .... I'm currently climbing the WPF / XAML learning curve ... only so many new concepts can be stuffed into my noggin in short periods of time ;-) .... Regards, Douglas |
|