472,993 Members | 3,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Re: iteration (property grid)

Well, what exactly do you want to do?

PropertyGrid is really at the whim of System.ComponentModel - and
there are various ways of investigating properties; the most common
being TypeDescriptor.GetProperties(). The tricky bit is sub-
properties, since to walk everything you'd need to look at
TypeConverters - it wouldn't be much fun.

Did you see the PropertyGrid/error-provider example I did for you the
other day? This might be an option. Alternatively you can provide your
own custom tab that could make this data more public (since it is tabs
that are asked to provide properties).

Alternatively, you might use IDataErrorInfo directly, since this is
the same validation that drives (as one example) the validation in

So; what exactly do you want to do?

Jun 27 '08 #1
4 1897
I have only one level of properties field ,don't have sub fields. So is
there a good solution for that case? All I need it to iterate through
them and to check if the values are valid.
Thanks again!
*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #2
Well, there are various ways of enumerating the properties, but I'm not
sure how that helps you validate things... you are going to have to find
some fun ways of validating arbitrary properties. That is why I
suggested IDataErrorInfo, as this provides a supported mechanism for an
object to validate *itself* and report any inconsistencies.

For enumerating the properties of an object, the simplest approach is
something like:

foreach(PropertyDescriptor prop in TypeDescriptor.GetProperties(obj))
Console.WriteLine("{0}={1}", prop.Name, prop.GetValue(obj));

However, note that PropertyGrid is a highly customisable control. For
example, it applies attribute-based filtering to properties (defaults to
[Browsable(true)], and allows individual tabs to shim other members as
properties - for example the "events" tab in VS.
Thus, if you have a complex setup, then to get the same list of
properties that PropertyGrid is using, you would have to do something like:

Attribute[] attribs =
new Attribute[grid.BrowsableAttributes.Count];
grid.BrowsableAttributes.CopyTo(attribs, 0);

foreach (PropertyDescriptor prop in
grid.SelectedTab.GetProperties(grid.SelectedObject , attribs))
prop.Name, prop.GetValue(grid.SelectedObject));

But again - unless you have some metadata-based idea for validing
individual properties, I'm not sure how this is going to help you...

Jun 27 '08 #3

but in the following code :
prop.Name, prop.GetValue(grid.SelectedObject));
I don't have grid.SelectedObject ,I want I am doing it this way :

(prop.DisplayName,prop.Value??) How can I get a value associated with
current property in the iteration ? I can't do it with SelectedObject
because i am going over the values on load and not on click.
Thank u!

*** Sent via Developersdex http://www.developersdex.com ***
Jul 1 '08 #4
The SelectedObject is, confusingly, nothing to do with a selection; it
simply holds the object that we want to display properties for. You have
to have an object to use PropertyGrid...

(not to be confused with SelectedGridItem, which *is* related to a
regular selection).

Jul 1 '08 #5

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

Similar topics

by: Raymond Hettinger | last post by:
Here is a discussion draft of a potential PEP. The ideas grew out of the discussion on pep-284. Comments are invited. Dart throwing is optional. Raymond Hettinger ...
by: Andreas Poller | last post by:
Hi, I want to customize a Property Grid in the following way: The Property Grid should show a property which value should be changed by a dropdown-listbox. For example, there is a property...
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
by: Steve Teeples | last post by:
I was wondering if there is a way to force a property within a property grid to update and then display a modified value when when a second property (true/false) is toggled? -- Steve
by: aldonnelley | last post by:
Hi all. Just having a weird problem with tkinter. I'm trying to make a gui that shows results from an image search, with a "forward" and "back" button so the user can compare results from...
by: Hans Koller | last post by:
Hello group, I design a class to bind it to a property grid for easy modification of some settings. My problem is now that I want to raise an event when a settings has been changed. Thats not a...
by: srpiton | last post by:
Hello everybody. Anybody has any ideas with the following problem? We start with a list, and we wish to construct a generator that yields each element of the list exactly once, but in random...
by: asharda | last post by:
I have a custom property grid. I am using custom property grid as I do not want the error messages that the propertygrid shows when abphabets are entered in interger fields. The custom property...
by: Derek Hart | last post by:
I can set focus to my property grid by using propgrid.Focus - but how can I set the default property that is always first? Or just set focus to the default property? Can this be done?
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.