locked
Properties.Settings Not showing in grid format RRS feed

  • Question

  • Hi folks,

    I had just installed Visual Studio into a new PC. WHen I load my existing solution the Properties.Settings used to appear in a grid format. Now they are showing as an XML file. 

    Also when the program refers to the settings in code, the program crashes...

    try
                {
                    // Restore columns state
                    StringCollection cols = Properties.Settings.Default.OR_OrdersGridColumn;
                    string[] colsArray = new string[cols.Count]; // crashes here - : 'Object reference not set to an instance of an object.'

    Am I missing something ?

    Thanks,

    John


    jppnn

    Tuesday, May 5, 2020 10:15 AM

Answers

  • Hi folks,

    I went back to VS 2017 and now it is working fine. Must be a VS 2019 flaw.

    Thanks again for all the help,

    J


    jppnn

    • Marked as answer by john pp nn Wednesday, May 6, 2020 12:44 PM
    Wednesday, May 6, 2020 11:33 AM

All replies

  • Questions

    • How did you get the existing solution to the new machine, copy and paste, a pull from something like GitHub
    • Is the version of Visual Studio the same as the version of Visual Studio it was created in.
    • Same .NET Framework on both machines?
    • Both machines the same OS ?
    • Which grid ???
    • Are the settings in app.config ???
    • What is in cols? put a breakpoint on the next line and peek in a debug session, is it null ???

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, May 5, 2020 4:22 PM
  • Hi Karen,

    The files are on a server and NOT on the local machine.

    I think it was maybe 2017 that was previously installed. But I would not have thought that would have made a difference.

    Both were on Dot Net 4.5 on Windows 10

    On debugging the code below...

    StringCollection cols = Properties.Settings.Default.OR_OrdersGridColumn;
    
    // cols = null so next line fails.
    string[] colsArray = new string[cols.Count];

    They were stored in Properties.Settings of a project. Below is a pic of what it should look like..

    The pic below shows what is what I am getting now.

    I would have thought the VS would create the properties if they did not already exist on a PC. I'm not even sure where they would be stored. Have looked but cant seem to find them.

    Hope this helps,

    John


    jppnn




    • Edited by john pp nn Tuesday, May 5, 2020 7:01 PM
    Tuesday, May 5, 2020 6:53 PM

  • Hi john pp nn,
    >>StringCollection cols = Properties.Settings.Default.OR_OrdersGridColumn
    I viewed your description, what is your requirememnt? And could you explain what OR_OrdersGridColumn is?
    When you set your custom settings,it will shows in the App.config(Settings.settings).
    If you want it appears in a grid format, you can use a PropertyGrid control to achieve this.

    propertyGrid1.SelectedObject = Properties.Settings.Default;
    UserScopedSettingAttribute userAttr = new System.Configuration.UserScopedSettingAttribute();
    System.ComponentModel.AttributeCollection attrs = new System.ComponentModel.AttributeCollection(userAttr);
    propertyGrid1.BrowsableAttributes = attrs;

    More details you can refer to this document.
    And you can get the value from the setting directly by followinng code:

    string hasAdobeReader = Settings.Default.hasAdobeReader;
    string hasExcle = Settings.Default.hasExcle;

    You can also get the value from the propertyGrid control by referring to Ali Ahmadi answer.
    Best Regards,
    Daniel Zhang


    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.

    Wednesday, May 6, 2020 7:14 AM
  • Hi folks,

    I went back to VS 2017 and now it is working fine. Must be a VS 2019 flaw.

    Thanks again for all the help,

    J


    jppnn

    • Marked as answer by john pp nn Wednesday, May 6, 2020 12:44 PM
    Wednesday, May 6, 2020 11:33 AM