none
Object Reference not set to an instance of an object in Background image RRS feed

  • Question

  • Hi All,

    I am using custom editor collection for a property(which contains the collection of custom controls)  in custom control. I have used the UITypeEditor for this proeprty as given in this link . Now when clicking the property, UI editors shows but when clicking the background image it shows the following error.

    

    Can anyone please help me to resolve this?

    Monday, February 12, 2018 9:52 AM

All replies

  • Hi Vinothini,

    Just as the message said, you did not set an instance for an object, in fact, this is a general error, you need to give a specific instance before you use an object, I'm not sure what object, because it is also widespread.

    Or maybe you can provide the code or project with OneDrive for my test.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 13, 2018 5:51 AM
    Moderator
  • Hi Stanly

    Sorry for the delay in getting back to you.

    Please find the reproducible sample in here.

    Click the usercontrol in the designer and open the property window click the QuickItems, the add one item from the combobox. Then click the items and properties will be listed in the PropertyGrid. Now click Image or BackgroundImage property , then the exception message will be thrown.

    Video to reproduce the issue here.

    Regards,

    Vinothini

    Thursday, February 22, 2018 12:08 PM
  • Hi Stanly,

    The issue is still being reproduced in our source , can you please have a look in the attached sample and video in the last comment and revert us.

    Regards,

    Nikhilesh 

    Monday, June 3, 2019 11:19 AM
  • Hi Team,

    Can you please update on this.

    Sample - https://drive.google.com/open?id=1RlclqtMib6FrmONVGm8DcILZb4cFwHC3 

    Video - https://drive.google.com/file/d/1CgHJA9Qxt_2a1Mxyh5OLn7GCThjyS5ma/view?usp=sharing

    Regards,

    Nikhilesh O

    Wednesday, August 21, 2019 5:49 AM
  • Hi All,

    As our release is coming soon, so can you please update on this.

    Thanks,

    Nikhilesh O

    Wednesday, September 11, 2019 11:39 AM
  • Hi All,

    Is there any solution available for this?

    Regards

    Vijayalakshmi V.R.

    Wednesday, September 25, 2019 5:30 AM
  • Hi All,

    Can you reply me any suggestion on this?

    Thanks,

    Vijayalakshmi V.R.

    Thursday, October 3, 2019 5:40 AM
  • Hi guys,

    I'm facing a similar issue as well. Can you provide me a solution for this?

    Thursday, October 10, 2019 6:14 AM
  • Hi All

    Please update us any suggestion available for this?

    Regards

    Vijayalakshmi V.R.

    Thursday, October 17, 2019 6:11 AM
  • Hi All,

    Can anyone please let me know is any solution available for this?

    Regards

    Vijayalakshmi V.R.

    Thursday, October 24, 2019 5:23 AM
  • Hi All

    Please let me know is any solution available for this?

    Regards

    Vijayalakshmi V.R.

    Thursday, October 31, 2019 6:31 AM
  • Hi All 

    Please let us know if any possibilities to achieve this requirement.

    Regards

    Vijayalakshmi V.R.

    Thursday, November 7, 2019 4:33 AM
  • Hi All

    Please let us know is any possible solution available for this to meet the requirement.

    Regards

    Vijayalakshmi V.R.


    • Edited by Vijinew Thursday, November 14, 2019 4:38 AM
    Thursday, November 14, 2019 4:38 AM
  • Hi All

    Please tell is any possibility available for this.

    Regards

    Vijayalakshmi V.R.

    Thursday, November 21, 2019 6:17 AM
  • Hi All

    Can you please reply on this.

    Regards

    Vijayalakshmi V.R.

    Thursday, November 28, 2019 4:30 AM
  • Hi All,

    Can you please tell is any other possibilities available for the reported requirement .?

    Regards,

    Vijayalakshmi V.R.

    Thursday, December 12, 2019 4:40 AM
  • Hi All,

    Please reply if any possibility approach is there to achieve the reported requirement?

    Regards,

    Vijayalakshmi V.R.

    Monday, December 30, 2019 4:21 AM
  • Hi Vinothini,
     
    I downloaded your code and your video. I played with it for a while this morning and could not figure out why the "Select Resource" appeared to be missing (that's what should have come up, when instead it crashed).
     
    Then, after lunch, I found this:
     
    https://social.msdn.microsoft.com/Forums/windows/en-US/3b61d081-ff6b-44d8-b82b-d35006a5a4e0/select-resource-dialog-and-custom-uitypeeditor-issue?forum=winformsdesigner

    It appeared to have the answer, so I made a few changes in your code, and sure enough ... it works now!!


    Here's what I changed, in bold (all in the QuickItems.cs file):

    In the QuickItems constructor, add ISite as a parameter and set the propertyGrid1.Site property:

    public QuickItems(UserControl1 user, IWindowsFormsEditorService editorService, ISite site)
    {
        InitializeComponent();
        ts1 = ts2 = ts3 = ts4 = ts5 = ts6 = 1;
        ts7 = ts8 = ts9 = ts10 = ts11 = ts12 = ts13 = 1;
        m_user = user;
    
        // I added this
        this.propertyGrid1.Site = site;
    }
    


    And, in the QuickItemEditor, the site needs to be set in the EditValue() method and passed to the QuickItems() constructor:

    public override object EditValue(    ITypeDescriptorContext context,    IServiceProvider provider,    object value)
    {
        if (provider != null)
        {
            editorService =
                provider.GetService(
                typeof(IWindowsFormsEditorService))
                as IWindowsFormsEditorService;
        }
    
        if (editorService != null)
        {
            QuickItemCollections coll = value as QuickItemCollections;
            UserControl1 owner = coll.userControl;
    
            // I add this
            IComponent comp = context.Instance as IComponent;
            ISite site = comp == null ? null : comp.Site;
            //
    
            // and changed this
            //QuickItems collEditorFrm = new QuickItems(owner,editorService);
            QuickItems collEditorFrm = new QuickItems(owner, editorService, site);
            //
    
            context.OnComponentChanging();
            if (editorService.ShowDialog(collEditorFrm) == DialogResult.OK)
            {
    
                context.OnComponentChanged();
                collEditorFrm.ShowDialog();
               
                value = owner.QuickItems;
            }
        }
        return value;
    }

    It all worked when I did that, so I'm pretty sure that will take care of it.

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Wednesday, January 1, 2020 10:26 PM