This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, I have this in my class: public Dictionary<string, string> Name { get; set; } For some reason I can't add new key-value pairs to it with the propertygrid, there's no that plus sign like with List<>. Is there some simple thing I'm missing here? Thanks! :) |
|
|
The grid doesn't provide a built-in way to add items to a dictionary because it has no way of requesting a key for the newly added item. (With a List, of course, this isn't an issue.) However, you can customise the display of the dictionary item using a PropertyEditor or TypeEditor, and within that editor provide your own UI for adding items, which could e.g. display a dialog box to request the key. Don't forget to set AllowExpand="True" on the editor so that users can still expand the dictionary and get at the contents. Let me know if you need more info about how to do this. Also note that if you want to add items to a collection and have them show up automatically in the grid, the collection must implement INotifyCollectionChanged. The .NET Dictionary class doesn't do this, but the grid library includes an ObservableDictionary collection which you can use instead. |
|