|
Hi guys,
Can anyone tell me how to invoke / display the default collection editor dialog box for a DataGridView.
I'll just explain what I've done so far. I've created a custom class that inherits from DataGridView. Added various custom methods and propertiesto the class.Created a ControlDesigner and a SmartTag.
As a result of creating a smart tag I've lost the 'Edit Columns...' and 'Add Columns...' options from the default smart tag. I haven't edited the underlying column collection or provided a new one. I want to have a customDesignerActionMethodItem open the collection editor for base.Columns i.e. DataGridViewColumnCollectionEditor. Can anyone point in me in the right direction for getting a type editor for a given property and then opening it programmatically? Somewhat like clicking the '...' ellipse next toColumns in the PropertyGrid.
I want to accomplish the same thing for the DataGridView Rows collection as well, so something generic would be gratefully appreciated.
Cheers,
James
Please vote on the content of this post, or if it answered your question please do not forget to 'Mark As Answer' | | Irish Newton Wednesday, February 25, 2009 4:15 PM |
Hi Irish Newton,
Base on my test, it is quite difficult to accomplish this. Since DataGridView use "DataGridViewDesigner", your "ExtendedDataGridDesigner" inherite from "ControlDesigner", "DataGridViewDesigner" is an internal class so you cannot inherited from it. But inherite from "ControlDesigner" need you write a lot of code to implement the "DataGridViewDesigner" then add your own function.
You can use "Reflector" to view the code of "DataGridViewDesigner", quite long code. I try to copy them to my project so your "ExtendedDataGridDesigner" class can directly inherite from it. But I faild, many class the "DataGridViewDesigner" used are also internal(such as: DataGridViewAddColumnDialog). If you want to compile all the code, you need to get all the source code from the Reflector.
.Net Reflector: http://www.red-gate.com/products/reflector/
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer byKira QianMSFT, ModeratorThursday, March 05, 2009 1:45 AM
-
| | Kira Qian Tuesday, March 03, 2009 4:06 AM |
Hi Irish Newton,
The designer editor of DataGridView.Columns property is the "System.Windows.Forms.Design.DataGridViewColumnCollectionEditor". The Columns property cannot be override, so I don't know how it is destroyed. May be you need to provide the code of your custom DataGridView and let us to test it.
Hint: Don't select the "Display line number" in the code format dialog. It will be easy fo me to copy the code.
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. | | Kira Qian Friday, February 27, 2009 2:58 AM | Hi Kira, Thanks for getting back to me, sure I'd be happy to provide some sample code to demonstrate what I am trying to accomplish. Three classes below, the object, its designer and an action list - I've stripped it down as much as possible. You should be able to recreate using what's below. Ultimately I need to be able to open the columns collection editor programatically from my custom smart tag.
| usingSystem.ComponentModel; |
| usingSystem.Windows.Forms; |
|
| namespaceEDG{ |
|
| [Designer(typeof(ExtendedDataGridDesigner))] |
| publicclassExtendedDataGrid:DataGridView{} |
| } |
| usingSystem.ComponentModel.Design; |
| usingSystem.Windows.Forms.Design; |
|
| namespaceEDG{ |
|
| publicclassExtendedDataGridDesigner:ControlDesigner{ |
|
| privateDesignerActionListCollectionactionLists=null; |
|
| //Usepullmodeltopopulatesmarttagmenu. |
| publicoverrideDesignerActionListCollectionActionLists{ |
| get{ |
| if(actionLists==null){ |
| actionLists=newDesignerActionListCollection(); |
| actionLists.Add(newExtendedDataGridActionList(this.Component)); |
| } |
| returnactionLists; |
|
| } |
| } |
| } |
| } |
| usingSystem; |
| usingSystem.ComponentModel; |
| usingSystem.ComponentModel.Design; |
|
| namespaceEDG{ |
|
| publicclassExtendedDataGridActionList:DesignerActionList{ |
|
| privateExtendedDataGridedg; |
| privateDesignerActionUIServicedesignerActionUISvc=null; |
|
| //Theconstructorassociatesthecontrol |
| //withthesmarttaglist. |
| publicExtendedDataGridActionList(IComponentcomponent) |
| :base(component){ |
|
| this.edg=componentasExtendedDataGrid; |
|
| //CacheareferencetoDesignerActionUIService,sothe |
| //DesigneractionListcanberefreshed. |
| this.designerActionUISvc=GetService(typeof(DesignerActionUIService))asDesignerActionUIService; |
| } |
|
| //Helpermethodtoretrievecontrolproperties.Useof |
| //GetPropertiesenablesundoandmenuupdatestoworkproperly. |
| privatePropertyDescriptorGetPropertyByName(StringpropName){ |
| PropertyDescriptorprop=null; |
| prop=TypeDescriptor.GetProperties(edg)[propName]; |
| if(null==prop) |
| thrownewArgumentException("MatchingExtendedDataGridpropertynotfound!",propName); |
| else |
| returnprop; |
| } |
|
| //Mycustompropertiesliveinhere |
|
| //ThisisthemethodwhichshouldopenthegenericdefaultcollectioneditorforDataGridView.Columnscollection. |
| publicvoidShowEditDialog(){ |
| //WhatIwouldliketodo:(i.e.createnewandthencallshow-butitdoesn'tcompile) |
| //System.Windows.Forms.Design.DataGridViewColumnCollectionEditordia=newSystem.Windows.Forms.Design.DataGridViewColumnCollectionEditor(); |
| //dia.Show(); |
| } |
|
| //Implementationofthisabstractmethodcreatessmarttag |
| //items,associatestheirtargets,andcollectsintolist. |
| publicoverrideDesignerActionItemCollectionGetSortedActionItems(){ |
| DesignerActionItemCollectionitems=newDesignerActionItemCollection(); |
| items.Add(newDesignerActionMethodItem(this,"ShowEditDialog","EditColumns...")); |
| returnitems; |
| } |
|
| } |
| } | I've commented out the two crucial lines in ExtendedDataGridActionList.ShowEditDialog() that are supposed to call the editor. I guess I need some form of reflection to get the type, perhaps cast it to a generic System.Windows.Forms.Form an then call Show. Any ideas??? Many Thanks, James
Please vote on the content of this post, or if it answered your question please do not forget to 'Mark As Answer' | | Irish Newton Monday, March 02, 2009 10:28 AM |
Hi Irish Newton,
Base on my test, it is quite difficult to accomplish this. Since DataGridView use "DataGridViewDesigner", your "ExtendedDataGridDesigner" inherite from "ControlDesigner", "DataGridViewDesigner" is an internal class so you cannot inherited from it. But inherite from "ControlDesigner" need you write a lot of code to implement the "DataGridViewDesigner" then add your own function.
You can use "Reflector" to view the code of "DataGridViewDesigner", quite long code. I try to copy them to my project so your "ExtendedDataGridDesigner" class can directly inherite from it. But I faild, many class the "DataGridViewDesigner" used are also internal(such as: DataGridViewAddColumnDialog). If you want to compile all the code, you need to get all the source code from the Reflector.
.Net Reflector: http://www.red-gate.com/products/reflector/
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer byKira QianMSFT, ModeratorThursday, March 05, 2009 1:45 AM
-
| | Kira Qian Tuesday, March 03, 2009 4:06 AM |
|