473,320 Members | 1,902 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,320 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
DataGridView.

So; what exactly do you want to do?

Marc
Jun 27 '08 #1
4 1920
Hello,
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))
{
Console.WriteLine("{0}={1}",
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...

Marc
Jun 27 '08 #3


but in the following code :
Console.WriteLine("{0}={1}",
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).

Marc
Jul 1 '08 #5

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

Similar topics

35
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 ...
0
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...
0
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...
3
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
3
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...
0
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...
2
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...
1
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...
10
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?
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.