473,396 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with the filtering of a property grid

Hello.

I created a designer in c#. Everything is working excepted the
property grid.

I want to show only the properties I added. So I created a class which
inherits of a button. And I added properties.

But I want to filter the base properties. So to do this, I inherit my
class from ICustomTypeDescriptor.

In the function getProperties, I filter. And I can show only my
properties. But on my host designer, the text of my button and the
position disappeared.

I mean when I add my custom button without filtering. I see it normal.
And if I filter, the text and position are removed. So it appears in
the left corner and I can't move it.

How can I fix the problem?

Thank you.
Jun 27 '08 #1
8 2984
Can I double check? It sounds like you are hosting a PropertyGrid in
your app, and want to filter the propeties that appear inside your app,
while leaving the regular VS IDE "as is" - correct?

You can use the BrowsableAttributes property to specify a filter based
on attributes; by default, it uses:
new Attribute[] {BrowsableAttribute(true)}
Which hides properties with BrowsableAttribute(false) - but you can
specify your own. Alternatively, you can implement your own PropertyTab
(remove the default one, add yours instead) - and simply override
GetProperties in PropertyTab; that way you have complete control.

Marc
Jun 27 '08 #2
And here's an example of both approaches...

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;

public class Foo
{
[MyAttribute]
public int BrowseNotSetWithCustom {get;set;}
[Browsable(true)]
public int BrowseTrueNoCustom {get;set;}
[Browsable(false), MyAttribute]
public int BrowseFalseWithCustom {get;set;}
}

class MyAttribute : Attribute {}
static class Program
{
static void Main()
{
// have 3 grids; one default, one using custom
// attributes, one using custom tab
Foo foo = new Foo();
Application.EnableVisualStyles();
PropertyGrid customGrid = new PropertyGrid
{
Left = 400,
Height = 400,
SelectedObject = foo,
BrowsableAttributes = new AttributeCollection()
};
customGrid.PropertyTabs.AddTabType(typeof(MyTab),
PropertyTabScope.Static);
Application.Run(
new Form {
Width = 800,
Height = 450,
Controls = {
new PropertyGrid {
Left = 0,
Height = 400,
SelectedObject = foo
},
new PropertyGrid {
Left = 200,
Height = 400,
BrowsableAttributes = new AttributeCollection(
new MyAttribute()),
SelectedObject = foo
},
customGrid
}
}
);
}
}
public class MyTab : PropertyTab
{
public MyTab() {

}
public override System.Drawing.Bitmap Bitmap
{
get
{
return SystemIcons.Shield.ToBitmap();
}
}
public override bool CanExtend(object extendee)
{
return true;
}
public override PropertyDescriptorCollection
GetProperties(ITypeDescriptorContext context, object component,
Attribute[] attributes)
{
return GetProperties(component, attributes);
}
public override PropertyDescriptorCollection GetProperties(object
component)
{
return GetProperties(component, null);
}
public override PropertyDescriptorCollection GetProperties(object
component, Attribute[] attributes)
{
PropertyDescriptorCollection props =
TypeDescriptor.GetProperties(component, attributes);
List<PropertyDescriptorlist = new
List<PropertyDescriptor>(props.Count);
foreach (PropertyDescriptor prop in props)
{
if (prop.Name == "BrowseTrueNoCustom") continue; // skip
list.Add(prop);
}
return new PropertyDescriptorCollection(list.ToArray());
}
public override string TabName
{
get { return "Mwahahah"; }
}
}
Jun 27 '08 #3
Thank you marc for your sample. But I can't compile it. I have VS2005

Could you give me an example which works with VS2005. Moreover, I
didn't understand, why I need to use three propertygrid.

Could you please explain me? Thank you
Jun 27 '08 #4
Ok well I worked a lot and I fixed the problem. Thanks a lot Marc.

Just a question. When I want to add a component to my host designer, I
would like to show the picture of my component as visual. Do you how
can I do that?

Thanks

Jun 27 '08 #5
Ok well I worked on my problem. And it is fine. i fixed the problem.
Thanks a lot.

But i have an other question. Do you know how can I show the picture
of the component I want to add to my host designer when I chose it in
the toolbox?

Thanks alot for your help.
Jun 27 '08 #6
But I can't compile it. I have VS2005
From your later post, it sounds like this is sorted - but please let
me know if it isn't: I can port it to C# 2 easily enough (it just
takes more typing...)
I didn't understand, why I need to use three propertygrid.
The three grids was merely to show the difference between the standard
behaviour, the behavior with a different attribute filter, and the
behavior with a custom tab.

Marc
Jun 27 '08 #7
Just a question. When I want to add a component to my host designer, I
would like to show the picture of my component as visual. Do you how
can I do that?
Can you be more specific? Where do you want it to be graphic? For
example, you can specify a toolbox bitmap (from a file or a resource
inside the assembly) with ToolboxBitmapAttribute:
http://msdn.microsoft.com/en-us/libr...attribute.aspx

Or if you mean inside the property-grid (like how images, colours etc
hav a preview), this is the job of a UITypeEditor.

Marc
Jun 27 '08 #8

When I choose a component in my toolbox to add it to my designer, I
have a cross as cursor. And I would like to show the picture of the
component near the cursor as visual studio is doing.

Do you have an idea?

I have a last question. Sorry for my bad knowledge. I have firefox and
I installed piclens. The user interface is really cool and I would
like to create the same or closer. Do you think I can create it with
Visual Studio 2005 desktop application? Maybe I can use DirectX. Do
you have an other idea?

An other solution will be to se csharp 3.0. What could you advice me?

Thanks a lot. I really apreciate your help.
Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Amar | last post by:
I am trying to connect to my college LDAP directory using ASP.NET. This LDap does not have security as it returns only user demographic information. i do not need to bind with a username or...
0
by: CSDunn | last post by:
Hello, I have a problem with field filtering between an Access 2000 Project form (the application is called CELDT), and the report that shows the results of the filter. Both the form and the...
2
by: Mevar81 | last post by:
Hi to everybody.I have a problem with the PropertyGrid control.I want to display not all the properties of a generic Control(Button,TextBox,ComboBox,ecc.).In general I don't want to display only...
3
by: asad | last post by:
Hello, i want to filter my records in ASP.NET pls tell me how can i do it thanks
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
5
by: DBC User | last post by:
I have a data set which has a data table. This dataset is set as a datasource for a display grid. Before I assign the data set to data grid, I would like to elliminate some rows from the data...
2
by: kevinpond | last post by:
I have a Gridview displaying the results of a stored procedure. The stored procedure is constantly changing so the columns displayed in the data grid are constantly changing. I'd like to give...
0
by: sjoshi | last post by:
Hello All I'm trying to use a filter with collectiong derived off BindingList and I see that if I use the foreach way of adding and checking the item then I get instant feedback on the grid. If...
0
by: Lyn | last post by:
I have a problem using the form .Filter and .FilterOn properties which causes Access to crash (as detailed in a separate post). The form operates in continuous mode, displaying matching records...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.