Trouble with properties

Marc Graham 26 Reputation points
2024-03-23T20:44:46.6766667+00:00

I defined a property, defined in settings, that the user can modify by adding more items to it. A lot of junk has accumulated that I can't get rid of.

        private DataGridViewComboBoxColumn createComboBox(colHdrInfo cHI) {
#if FIXBOX
            Properties.Settings.Default.typeList = String.Join(",",allowedTypes);
#else
            allowedTypes = Properties.Settings.Default.typeList.Split(',');
#endif
            Array.Sort(allowedTypes);
            _acsc.AddRange(allowedTypes);
            DataGridViewComboBoxColumn blah = new DataGridViewComboBoxColumn()  {
                HeaderText = cHI.ToString(),
                Name = cHI.ToString(),
                DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing,
                SortMode = DataGridViewColumnSortMode.Programmatic,
            };
            blah.Items.Clear();
            blah.Items.AddRange(allowedTypes);
            Properties.Settings.Default.typeList = String.Join(",", allowedTypes);
            return blah;
        }
FIXBOX is defined to reset the property to a default list, the value of AllowedTypes. That seems to work, but if I close the application and then run without FIXBOX defined I get the old value. I'm at a loss.

P.S. I'd already tried the AI-generated suggestions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2024-03-23T20:44:46.68+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Based on the provided context, it seems that the user is having trouble with a property that is defined in settings and is used to populate a DataGridViewComboBoxColumn. The user mentioned that a lot of junk has accumulated in the property that they can't get rid of. It seems that the user is trying to reset the property to a default list, but when they close the application and run it again without resetting the property, they get the old value.

    It is unclear what kind of junk has accumulated in the property, but it seems that the user is trying to reset the property to a default list of allowed types. The user is using a conditional compilation symbol FIXBOX to reset the property to the default list. However, it seems that this approach is not working as expected.

    Without more information on what kind of junk has accumulated in the property, it is difficult to provide a specific solution. However, one approach that the user can try is to clear the typeList property before resetting it to the default list. This can be done by adding the following line of code before resetting the property:

    Properties.Settings.Default.typeList = "";
    

    This will clear the typeList property before resetting it to the default list.

    Another approach that the user can try is to debug the application and see why the property is not being reset to the default list. They can use breakpoints and watch windows to inspect the value of the property at different points in the code and see where it is being set to the old value.


    References:

    0 comments No comments