Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a user control which I want to create a dll and use it in other project.

I have Property in that user control which should show a combo box in propertygrid contains all forms in the referenced project.I have to select one of that form to set the property value.

I Created the following custom UITypeEditor

internal class EntryFormEditor : ObjectSelectorEditor
      {
          protected override void FillTreeWithData(Selector theSel,
            ITypeDescriptorContext theCtx, IServiceProvider theProvider)
          {
              base.FillTreeWithData(theSel, theCtx, theProvider);  //clear the selection
              GrbDataGridView aCtl = (GrbDataGridView)theCtx.Instance;

              Type formType = typeof(Form);
              try
              {
                  //foreach (Assembly currentassembly in AppDomain.CurrentDomain.GetAssemblies())
                  //{
                  foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
                      {
                          if (formType.IsAssignableFrom(type))
                          {
                              try
                              {
                                  SelectorNode aNd = new SelectorNode(type.Name, type);

                                  theSel.Nodes.Add(aNd);
                              }
                              catch (Exception ex)
                              {
                              }
                              //if (type ==(Form) aCtl.EntryFormName)
                              //    theSel.SelectedNode = aNd;
                          }
                      //}
                  }
              }
              catch (Exception ex)
              {
              }
          }
      }



but showing only the forms inside the dll and not in the referenced project


What did I done wrong . Can anyone please Help ?
Posted
Comments
BillWoodruff 22-Aug-13 9:55am    
First, if you want a UserControl compiled to a dll for re-use, why would it ever have "forms inside the dll" in the first place ?

I am slightly confused by what's asked in your question, and then what you say in later comments to replies here:

1. you mention using a PropertyGrid, and later a UserControl inheriting from DataGridView.

2. your code example, designed to use with a DataGridView (?), obviously uses Reflection to enumerate all the Types in the currently executing Assembly. That implies to me that you want to provide to the user, at run-time, a list that allows them to select all possible Form Types, which has no relationship to whether any of the Form Types have current instances. Am I way off-track here ?

Which implies that if the user selected a Form Type that was not currently open, you'd have to create an instance of it, if you don't already have an instance, and then show it, if it's hidden, make it active, bring it to the front, etc. Is that really what you want to do ?

IS IT POSSIBLE that what you really want to do here is to, at any given moment at run-time, to enumerate all the currently open Forms in a PropertyGrid in a UserControl sited on one of your forms (probably the "primary" Form") ?

If THAT is your goal, yes, it can be done (I've done it at the proof-of-concept level), and its not difficult. The "hard part" would be doing the right thing to get the ComboBox in the PropertyGrid set-up, and interact with it, and it looks, to me, like you may already have done that (?) ... which I have never done.
Jackson K T 23-Aug-13 3:26am    
Actually I'm trying to create a custom datagridview which can re use in other projects.

This datagridview has a custom property which can assign it's entry form ,ie. if the grid is displaying employee list ,if we set this property ,when clicking on a particular row in the grid redirect to employee entry form .

So I thought it will be helpful if I can select the entry form from propertygrid at design time.
Now I'm setting this property by code like

mydatagridview.EntryFormName = new employeeEntryform();

This is the property I created

[Browsable(true)]
[DefaultValue(null)]
Editor(typeof(EntryFormEditor), typeof(System.Drawing.Design.UITypeEditor))]
public Form EntryFormName { get; set; }

The code I posted in my Question is the class EntryFormEditor. This class is supposed to display all forms in my project in the propertygrid
BillWoodruff 23-Aug-13 11:23am    
Thanks, clearer now what you are doing. I think I have a proof-of-concept working for what you want to do, and I will post it, as soon as I am sure it's working. Something very strange: in WinForms, .NET 4.5, with "using System.ComponentModel.Design;" the 'ObjectSelectorType does not appear, and MSDN docs say it's there.

Have you already worked out how to raise the design-time event that you will have to trigger when the user makes a selection from one of the valid editor forms, so that, when your application is launched, the proper editor form is used ?

Try Assembly.GetEntryAssembly instead of Assembly.GetExecutingAssembly
 
Share this answer
 
Comments
Jackson K T 21-Aug-13 4:32am    
I tried GetEntryAssembly() and GetCallingAssembly too

my problem is if WindowsApplication1 is using the dll then I want to get all forms in WindowsApplication1
OriginalGriff 21-Aug-13 4:57am    
You can't - you have to query it for each assembly individually.
There is no way to get the contents of "this and all referenced assemblies" - partly because the .NET framework is wholly made up of Assemblies your app references! :laugh:
In this line
C#
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())

you're referring to the executing assembly (your dll). Change it to the actual assembly that you want to inspect.

[Edit]
Have a look at GetCallingAssembly[^].
Looks like you could use it in your dll's entry point to get the assembly of the immediate calling method. The link states some quirks, though.

And, since I have no idea of your application's control flow, it could as well return some assembly belonging to the .NET framework.
[/Edit]
 
Share this answer
 
v2
Comments
Jackson K T 21-Aug-13 4:30am    
That's my problem I want to get the assembly which is using this dll

for eg : if WindowsApplication1 is using the dll then I want to get all forms in WindowsApplication1
lukeer 22-Aug-13 8:00am    
I updated my answer.
Jackson K T 21-Aug-13 4:38am    
To get more clarity I will explain a little bit

I have user control inherited from datagridview which has a custom property named "EntryForm" . This property used to navigate to data entry form from the datagridview.So I need to list all available forms to select corresponding data entry form

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900