Howdy,
I came across Marc Gravell's elegant and witty solution to the problem posted by Matt ( title "C#/winforms: how to best bind a propertygrid and a System.Data.DataRow" ), and have used same solution in one of my applications.
Using some excerpts from Marc's code :
DataTable table = new DataTable();
table.Columns.Add("ID", typeof(int));
table.Columns.Add("Foo", typeof(int));
table.Columns.Add("Bar", typeof(string));
table.Columns.Add("Audit", typeof(DateTime));
table.Rows.Add(1, 14, "abc", DateTime.MinValue);
DataRow row = table.Rows.Add(2,13,"def", DateTime.MinValue);
table.Rows.Add(3, 24, "ghi", DateTime.MinValue);
RowWrapper wrapper = new RowWrapper(row);
wrapper.Exclude.Add("ID");
wrapper.Exclude.Add("Bar");
I was able to somehow make this work with a DataGridView; DataGridView uses the table as it's source, while every click on a row on DataGridView would be set as the SelectedObject for the propertyGrid1 ( using Marc's RowWrapper ), and it works perfectly. You might ask why I am doing this, meaning use both DataGridView and PropertyGrid; fact is, business requirement and narrow-minded management policies.
Anyway, I have now another dilemna; one of the columns in the table, say "Foo" for instance, ( which shows up in the PropertyGrid as one of the fields, by the way ), should be some sort of a drop-down list in the PropertyGrid. What I mean is, "Foo" should be a combobox containing a list of items derived from another DataTable. Also, is there a way to include some sort of description for each field item?
Could this be done? Marc Gravell mentioned something like " Note that you could do other things in this area to make some of the properties non-editable (IsReadOnly), or have a different caption (DisplayName), or category (Category) - by overriding other members in RowWrapperDescriptor. " as the end note to his post, and I was wondering is there is a way to do this.
Any theoretical advice is greatly appreciated. Thanks much.