PropertyGrid Help
-
I am using a property grid to analyze records from a database. In the case where I have an ID that is the key for a different table, I am wanting to show a drop down list. I have gotten it to work where it will display my object because I've overridden the ToString() method, but when coming back the other way (e.g. selecting a different value in the drop down) it is unable to convert from the string back to the object type that I had). Is there any way to do what I'm wanting? I understand that if all I want is to choose from a list of strings, it would work perfectly, but what I need is to get the ID for that string when it is selected and I need to get the string for that ID when the property drop down is loaded. Hope that makes sense? Thanks. -Matt
------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall
-
I am using a property grid to analyze records from a database. In the case where I have an ID that is the key for a different table, I am wanting to show a drop down list. I have gotten it to work where it will display my object because I've overridden the ToString() method, but when coming back the other way (e.g. selecting a different value in the drop down) it is unable to convert from the string back to the object type that I had). Is there any way to do what I'm wanting? I understand that if all I want is to choose from a list of strings, it would work perfectly, but what I need is to get the ID for that string when it is selected and I need to get the string for that ID when the property drop down is loaded. Hope that makes sense? Thanks. -Matt
------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall
You should implement your own TypeConverter in order to enable conversion from string type to integer type and vice versa. Implementing new type converter is an easy job. Here is a link to very good tutorial: From MSDN Another example: Descriptive Enumarations
-
You should implement your own TypeConverter in order to enable conversion from string type to integer type and vice versa. Implementing new type converter is an easy job. Here is a link to very good tutorial: From MSDN Another example: Descriptive Enumarations
Thanks for the reply. I appreciate it. I've actually used that document (from MSDN) and gone over the examples there several times and I don't see how you would actually convert from an integer to a string. In the example they give under the heading "Adding Domain List and Simple Drop-down Property Support", you'll see that they are only concerned with string types in the list. If I could guarantee that my strings are always unique (which, in actuality, they probably won't be), then I could just do a reverse lookup to get the integer back when I need to set a value. The exmple they provide in the MSDN doc gives a good way to use strings, but doesn't seem to pertain to having some different corresponding value than what is displayed in the drop down. Is that the section you are referring to or is there some other part you are talking about? Thanks again. -Matt
------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall
-
Thanks for the reply. I appreciate it. I've actually used that document (from MSDN) and gone over the examples there several times and I don't see how you would actually convert from an integer to a string. In the example they give under the heading "Adding Domain List and Simple Drop-down Property Support", you'll see that they are only concerned with string types in the list. If I could guarantee that my strings are always unique (which, in actuality, they probably won't be), then I could just do a reverse lookup to get the integer back when I need to set a value. The exmple they provide in the MSDN doc gives a good way to use strings, but doesn't seem to pertain to having some different corresponding value than what is displayed in the drop down. Is that the section you are referring to or is there some other part you are talking about? Thanks again. -Matt
------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall
Your welcome! Now, to pertain id to its string, obviously you will create an object that have two properties (id and value) and override the ToString() to display the value. Ok, now if you use standatd listbox control in windows forms application, all objects that you will append to this control will be displayed using the string retrieved by calling to the ToString() method you just implemented. This leads you to what we call "CustomEditor". With CustomEditor you can create your own windows form like application to display and manage the property - so create one with listbox control to retrieve the records from the second table and adding them using the custom object you have just created. The last section in the mentioned MSDN article discusses this issue. Best regards, elaj