Property Grid Custom Search Box - c#

I have a PropertyGrid with a lot of nested items. How can I make a searchbox to filter and display only the items matching the search string?

Two ways -
Your best option is to implement ICustomTypeDescriptor interface and use the GetProperties() method to filter visible rows in PropertyGrid.
If you want to hack your way around - Using reflection set Browsable Attribute to false. Sample code
Here are some sample articles/links with code to implement ICustomTypeDescriptor -
http://wraithnath.blogspot.in/2011/01/implementing-icustomtypedescriptor-for.html
PropertyGrid Browsable not found for entity framework created property, how to find it?
http://www.codeproject.com/Articles/189521/Dynamic-Properties-for-PropertyGrid

Related

Add tooltip for PropertyGrid

I want to add a tool tip for items in a Property Grid. When the user hovers over a property I want the tooltip to display a hint about the usage of that property. The hint string should be different for each different value of the property — for example if one property is a list of strings each string would have a different hint.
Is this possible?
The PropertyGrid is not very flexible and doesn't expose any of the individual controls on it. You can access the control (textbox or dropdown) that you're looking to show the tooltip on via reflection but that is far from trivial, especially since all the control classes are unique and internal to the property grid.
Using the Description attribute is by far the best value. If your list of strings for that property aren't obvious enough to portray their meaning without providing a tooltip, perhaps you should revisit the string text you are showing for each item in the list.

How to add properties in PropertyGrid from the database?

I have around 30 elements/objects for which i need PropertyGrid to show their properties in it,but the problem is that every object has different properties so i created a database for it.
I don't know how to add properties in PropertyGrid from the Database.
I am going to assume that you are using Windows Forms, since you are asking about PropertyGrid. If you have objects (meaning classes) that have the properties you want to display in your PropertyGrid, you need only to set PropertyGrid.SelectedObject with the object you want to display. By default, PropertyGrid will use reflection to find all the public properties of your object, and will display them.
You can use various attributes to control how PropertyGrid displays properties. For example, you can apply the Description attribute to a class property to add help text that the property grid will display. You can use the Browsable attribute to control whether PropertyGrid will display a given property. There are other attributes in the System.ComponentModel namespace that you can use.

How to show or hide properties dynamically in the PropertyGrid?

I am using a PropertyGrid for configuring objects. I need to be able to hide or show some properties depending on the values of other properties. How this can be achieved? I know about Browsable attribute, but it only works at a compile time.
Take a look into the ICustomTypeDescriptor Interface.
Further informations on how to use it can be found in this article:
Bending the .NET PropertyGrid to Your Will.
Check this link Changing Browsable Property Attribute dynamically.A sample method is given.
Using Reflection access the Property and set its browsable property to true or false.

Making a proxy for ItemSource in a WPF Datagrid, is this possible?

In the project I'm currently working on, I don't have plain CLR objects to bind with my datagrid. Normally, I would use an ObservableCollection<MyObject>, but now I can't and instead I must use a custom object (which behaves like a DataTable but with custom logic).
My question is : How can I make a proxy/adapter object that will "translate" every binding operations on items in cells of my datagrid to my custom logic object?
Remember that:
My object is not a Collection, so I don't really have Items.
The "columns" of the virtual items might change.
Somewhere in the application I might change one value in that object and that the datagrid must reflect changes
Right now we are recreating a DataTable from the custom object to get his DataView to display in a datagrid and we intercept editing commands with events (which are ugly) and then reload everything from scratch each time when change a cell value.
I searched for hints about how to accomplish this but the things I found are :
IItemProperties interface (Might be interesting to have dynamic columns but I don't have a collection)
DataSourceProvider class (It appears to be a wrapper for ItemsSource, but I don't see what I have to return in the Data property)
INotifyPropertyChanged interface (To tell a property changed, but I don't have items or at least items don't have properties)
ICustomTypeDescriptor interface (Ok but once I returned the properties with GetProperties() how the datagrid will try to modify the inexistent property?)
As you can see, it's confusing about choosing a way to implement a good proxy.
Finally I found a solution, I used the second approach in this web site : and made an object that inherits from IBindingList and ITypedList to fake that the item is a list, I used also ICustomTypeDescriptor on each fake rows and called the master table object.
I would suggest creating kind of a ViewModel as an adapter between your Model (that mysterious object that is no collection but is viewed as one) and your View (the DataGrid). You will find various examples for this pattern when searching for Model-View-ViewModel.
Then you can define properties yourself, you only need to implement some suitable get/set-methods on your properties, to transfer ViewModel-changes to your original Model and vice versa (if needed).
Is .net 4.0 available. You can easy create a proxy by inheriting from DynamicObject (.net 4.0 only) whose dynamic properties will bind in xaml. If you proxy your DataTable you have to Implement INotifyCollectionChanged on a proxy for it and if you proxy your items you need To implement INotifyPropertyChanged on their proxy.

Is there a data-driven WPF property grid/editor available? (preferably free)

I'm looking for a data-driven WPF property grid/editor.
Most property grids appear to work using reflection to figure out the CLR properties on your class. Those properties are then displayed in the grid with editors that are specific for the type of the property.
However I don't have a specific class that I want to plug into the property grid. All I have is data, specifically a collection of name/value pairs. I want to put this collection into the grid and have a editor that is specific for the value type of each pair.
Does anyone know of an existing property grid/editor control that supports data-driven properties?
Also if it looks like the property grid/editor in Blend I won't complain ;)
I've never used it, but from what I've read about the PropertyTools for WPF on codeplex.com supports dynamically editting the current selected object.
http://propertytools.codeplex.com/

Categories

Resources