Answered Loading and Saving Collections without using Properties.Settings.Default

tim8w

Well-known member
Joined
Sep 8, 2020
Messages
131
Programming Experience
10+
Hi,
I have borrowed an implementation of Collections in a PropertyGrid that Loads and Saves the Collection data to the app.Settings. I have tried, but have failed to remove this so that I can eventually save the data out to my SQL Server database.

Here is my PropertyGridItems class:
C#:
using System;
using System.ComponentModel;
using System.Text;
using Defects;

namespace CustomCollectionApp
{
    internal class PropertyGridItems
    {
        [Editor(typeof(Defects.MyCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
        [Category("Defects")]
        [DisplayName("Defects")]
        [Description("A List of all the defects for this WO Number")]
        public DefectCollection Defects
        {
            get { return FirstPassYield.Properties.Settings.Default.DefectList; }
            set { FirstPassYield.Properties.Settings.Default.DefectList = value; }
        }
    }
}

Here is the Settings.Designer code:
C#:
        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute(@"
                    <ArrayOfDefect xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
                        <Defect>
                            <NumDefects>1</NumDefects>
                            <DefectCode>A03</DefectCode>
                            <DefectDesc>A03 Description</DefectDesc>
                        </Defect>
                    </ArrayOfDefect>
                ")]
        public global::Defects.DefectCollection DefectList
        {
            get
            {
                return ((global::Defects.DefectCollection)(this["DefectList"]));
            }
            set
            {
                this["DefectList"] = value;
            }
        }

and here is my Defects Class:
C#:
using System;
using System.Text;
using System.ComponentModel;

namespace Defects
{
    public class Defect
    {
        #region Private Variables

        private int numDefects;
        private string defectCode;
        private string defectDesc;
        private int numRejectReport;
        private string stringComment;

        #endregion

        #region Public Properties
        [Category("Defect")]
        [DisplayName("Num Defects")]
        [Description("The is the number of this type of defects.")]
        public int NumDefects
        {
            get { return numDefects; }
            set { numDefects = value; }
        }

        [Category("Defect")]
        [DisplayName("Defect Code")]
        [TypeConverter(typeof(DefectCodeTypeConverter))]
        [Description("The is the alpha-nueric defect code.")]
        public string DefectCode
        {
            get { return defectCode; }
            set { defectCode = value; }
        }

        [Category("Defect")]
        [DisplayName("Descripotion")]
        [TypeConverter(typeof(DefectDescriptionTypeConverter))]
        [Description("The is the description of the defect.")]
        public string DefectDesc
        {
            get { return defectDesc; }
            set { defectDesc = value; }
        }

        [Category("Defect")]
        [DisplayName("Reject Report Num")]
        [Description("The is the number of this type of defects.")]
        public int RejectReportNum
        {
            get { return numRejectReport; }
            set { numRejectReport = value; }
        }

        [Category("Defect")]
        [DisplayName("Comment")]
        [Description("Comment")]
        public string Comment
        {
            get { return stringComment; }
            set { stringComment = value; }
        }

        #endregion
        public class DefectCodeTypeConverter : TypeConverter
        {
            public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
            {
                return true;
            }

            public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
            {
                return true;
            }

            public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            {
                return new StandardValuesCollection(new string[] { "A01", "A01-a", "A01-b", "A01-c", "A02", "A03", "A04", "A04-a", "A04-b", "A05", "A05-a", "A05-b", "A06", "A07", "A07-a", "A07-b", "A08", "A09", "A10", "A11", "B01", "B02", "B03", "B04", "B05", "B06", "B07", "B08", "B09", "B10", "B11", "B13", "B14", "C01", "C02", "C03", "C04", "C05", "C06", "C07", "C08", "C09", "C10", "C11", "C12", "C13", "C14", "C15", "C16", "C17", "C18", "C19", "C20", "C21", "C22", "C23", "C24", "C25", "C26", "C27", "C28", "D01", "D01-a", "D01-b", "D02", "D02-a", "D02-b", "D02-c", "D02-d", "D03", "D04", "D05", "D06", "D07", "D08", "E01", "E02", "E03", "E04-a", "E04-b", "E05", "E06", "E07", "E08", "E09", "E10", "E11", "E11-a", "E11-b", "E11-c", "E11-d", "E11-e", "E11-f", "E11-g", "E11-h", "E12", "E12-a", "E12-b", "E12-c", "E12-d", "E12-e", "E12-f", "E12-g", "E12-h", "E13", "E14", "E15", "E15-a", "E15-b", "E16", "E16-a", "E16-b", "E17", "E17-a", "E17-b", "E18", "E18-a", "E18-b", "E18-c", "E18-d", "E18-e", "E18-f", "E18-g", "E18-h", "E19", "E19-a", "E19-b", "E19-c", "E19-d", "E19-e", "E19-f", "E19-g", "E19-h", "E20", "E20-a", "E20-b", "E20-c", "E20-d", "E20-e", "E20-f", "E20-g", "E20-h", "E21", "E22", "E23", "E24", "E24-a", "E24-B", "E25", "E25-a", "E25-b", "E26", "E27", "H01", "H02", "H03", "H03-a", "H03-b", "H04", "H05", "H06", "H07", "H07-a", "H07-b", "H07-c", "H07-d", "H07-e", "H08", "H08-a", "H08-b", "H08-c", "H08-d", "H08-e", "H09", "H09-a", "H09-b", "H10", "H11", "H12", "H12-a", "H12-b", "H12-c", "H12-d", "H12-e", "H13", "H14", "H15", "H16", "H17", "H18", "H19", "H20", "H21", "H22", "H23", "M01", "M02", "M03", "M04", "M05", "M06", "M06-a", "M06-b", "M07", "M08", "M09", "M10", "M10-a", "M10-b", "M10-c", "M11", "M11-a", "M11-b", "M11-c", "M12", "M13", "M14", "M15", "M16", "M20", "M21", "M22", "M23", "M24", "M26", "M27", "M28", "M29", "M30", "M31", "M31-a", "M31-b", "M32", "M33", "M34", "M35", "M36", "M37", "M38", "M38-a", "M38-b", "M39", "M40", "M41", "M42", "MA1", "MA2", "MA3", "NFF", "P01", "P02", "P03", "P04", "P05", "P06", "P07", "P08", "P09", "P10", "P11", "PR01", "PR02", "PR03", "PR04", "PR05", "PT01", "PT02", "PT03", "PT04", "PT05", "PT06", "PT07", "PT08", "PT09", "PT10", "PT11", "PT12", "PT13", "PT14", "PT15", "PT16", "PT17", "PT18", "PT19", "S01", "S02", "S03", "S04", "S05", "S06", "S07", "S08", "S09", "S10", "S11", "S12", "S13", "S14", "S15", "S16", "S17", "S18", "S19", "S20", "S21", "S22", "S23", "S24", "S25", "S26", "S27", "S28", "T01", "T02", "T03", "T04", "T05", "T06", "T07", "T08", "T09", "T10", "W01", "W02", "W03", "W04", "W06", "W09", "W10", "W11", "W12", "W13" });
            }
        }

        public class DefectDescriptionTypeConverter : TypeConverter
        {
            public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
            {
                return true;
            }

            public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
            {
                return true;
            }

            public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            {
                return new StandardValuesCollection(new string[] { "Damage Leadwires/Sleeving", "Damaged convolute tubing", "Damaged Insulation", "Damaged Shrink Tubing", "Improper Coil Orientation", "Improper Key Orientation", "Improper Leadwires/Sleeving Diameter", "Leadwire/ Sleeving Diameter Oversized", "Leadwire/ Sleeving Diameter Undersized", "Improper Leadwires/Sleeving Length", "Leadwire/ Sleeving Length too Long", "Leadwire/ Sleeving Length too Short", "Incorrect Assembly", "Incorrect Unit Weight", "Unit Under Weight", "Unit Over Weight", "Insufficient Painting", "Insufficient Plating", "Poor Workmanship Assy", "Wrong Hook Up", "Braze Voids", "Cracks Braze Joint", "Excessive Braze", "Insufficient Braze", "Washer to Washer Dimension Oversize", "Washer to Washer Dimension Undersize", "Voids/Excessive Pits/Pinholes/Porosity", "Excess Discontinuities", "C-Scan Failure", "Washer Depth Oversize", "Washer Depth Undersize", "Dimension Undersize", "Dimension Oversize", "Dirty Spool", "Insulation Length Short", "Tape Washer", "Missing Tape Washer", "Broken Wire", "Kink in Wire", "Damage Spool", "Wire Over Lapping", "Open Washer - Teflon", "Spool Mag Wire Damage", "Wrong Magnet Wire", "Missing Knot", "Wrong Hook-Up or Setup", "Not Enough Wire On Spool", "Coil Shorted", "Wrong Resistance Value on Resistance Wire", "Rewind Coil No Change", "Broken Wire", "Dirty Tape", "Flux on Joint", "Solder Splatter", "Copper on Tip", "Insufficient Solder", "Damage Lead Wire", "Damage Magnet Wire", "Oxidation Resist on Wire", "DC Mag Test (Short)", "Wrong Hook-Up", "Incorrect/Missing Documentation", "Missing / Incorrect 8130-3 Form", "Missing / Incorrect C of C", "Incorrect/Missing Identification", "Missing Label", "Missing Etching", "Incorrect Label", "Incorrect Etchig", "Incorrect/Missing Router", "Test Data - Certificate Missing", "Test Data - Incorrect/Incomplete", "Missing AS9102 FAI", "Incomplete AS9102 FAI", "Material Not DFAR Compliant", "Accuracy Out of Tol", "Bonding Resistance Out of Tol", "Cross Channel Interaction", "Short to Case", "Short Between Windings", "Failed Insulation - Arcing", "Insulation Dielectric Failed", "Insulation Shorting", "Linearity Out of Tol", "Null Voltage Out of Tol", "Null Position Out of Tol", "Open Primary", "Channel 1", "Channel 2", "Channel 3", "Channel 4", "Channel A", "Channel B", "Channel C", "Channel D", "Open Secondary", "Channel 1", "Channel 2", "Channel 3", "Channel 4", "Channel A", "Channel B", "Channel C", "Channel D", "Phase Reversed", "Phase Shift Out of Tol", "Primary DC Resistance Out of Tol", "Resistance High", "Resistance Low", "Primary Impedance Out of Tol", "Impedance High", "Impedance Low", "Sensitivity (Gain) Out of Tol", "Sensitivity High", "Sensitivity Low", "Shorted Between Windings", "Channel 1", "Channel 2", "Channel 3", "Channel 4", "Channel A", "Channel B", "Channel C", "Channel D", "Shorted Primary to Case", "Channel 1", "Channel 2", "Channel 3", "Channel 4", "Channel A", "Channel B", "Channel C", "Channel D", "Shorted Secondary to Case", "Channel 1", "Channel 2", "Channel 3", "Channel 4", "Channel A", "Channel B", "Channel C", "Channel D", "Summation Voltage Out of Tol", "Tracking Out of Limit", "Unbalanced Output", "Secondary DC Resistance Out of Tol", "Resistance High", "Resistance Low", "Secondary Impedance Out of Tol", "Resistance High", "Resistance Low", "Sensor Failed testing", "Stuck Output Signal", "Bent Armature", "Bent Spool Tube", "Cable Assy To Short", "Cable Assy Too Short", "Cable Assy Too Long", "Cable Diameter To Thick/Wide", "Connector ID Fading", "Contamination Dirty/Oily", "Damage Connector", "Pins are bent ", "Pins are pushed in", "Missing red/blue line", "Incomplete red/blue line", "Bronze powder is incomplete", "Damage Dents/Dings/Bent/Broken", "Dent on housing", "Ding on housing", "Bent Housing", "Cracked Housing", "Housing Scratched", "Damage Screw(s)", "Damaged Threading", "Stripped Head", "Discoloration of Leadwires", "Duplicate S/N on Test Data", "Etching Not Legible/Wrong", "Wrong Channel Identifiers", "Channel Identifiers are Swapped", "Wrong Kavlico Revision", "Wrong Customer Revision", "Duplicate Serial Number", "Holes in Sleeving", "Incorrect Processing", "Leadwires Broken Off", "Leadwires/Sleeving Stripes Fading", "Missing Sleeving", "Missing/Wrong Material", "Part Not Cleaned", "Reworked Failed", "Scratches on Unit", "Wrong Connectors", "Wrong Lead Gauge", "Angularity Not to Print", "Axial Play Out of Tol", "Broken Tap or Drill", "Burrs/Sharp Edges", "Chamfer Not to Print", "Concentricity Not to Print", "Armature Concentricity", "Housing Concentricity", "Damage Bearing", "Damage Crimp", "Damage Threads", "Diameter Oversize", "Housing Diameter", "Armature Diameter", "Extension End Diameter", "Diameter Undersize", "Housing Diameter", "Armature Diameter", "Extension End Diameter", "Distorted Feature", "Excessive Undercut", "Flatness Not to Print", "Hysteresis Binding", "Immersion Test Failed", "Linear Dimension Oversize", "Linear Dimension Undersize", "Locking Element Missing", "Mechanical Stroke Out of Tol", "Mislocated Feature", "Over Tapping", "Parallelism Not to Print", "Perpendicularity Not to Print", "Position Not to Print", "Pull Test Failure", "Radius Not to Print", "Radius Oversized", "Radius Undersized", "Roundness Not to Print", "Total Runout Not to Print", "Scrap or Rework per ECO", "Shield Problem", "Straightness/Symetry Not to Print", "Surface Finish Not to Print", "Threads Out of Tol", "Pressure Tube", "Coil Guide", "Tool Marks/Chatter", "Under Tapping", "Parts are leaking", "Loose Wires", "Damage Material", "Missing Material", "Wrong Material", "No Fault Found", "Bubbles in Potting", "Cracked Potting", "Excessive Potting", "Expired Potting Material", "Incorrect Potting Material/Mixed", "Incorrect Potting Weight", "Insufficient Potting Filling", "Potting Not Cured", "Potting Voids/Gaps", "Potting Wrong Cavity", "Reversion Solid to Liquid", "Improper Heat Treatment", "Improper Painting", "Improper Plating", "Operation Omitted", "Operation Performed Out of Order", "Wrong Hook-Up or Phasing", "High Null Voltage", "Input Impedance LOW", "Input Impedance HIGH", "Input DC Resistance LOW", "Input DC Resistance HIGH", "Output Impedance LOW", "Output Impedance HIGH", "Output DC Resistance LOW", "Output DC Resistance HIGH", "Phase Shift", "High Linearity", "Sensitivity LOW", "Sensitivity HIGH", "Output Voltage Ratios LOW", "Output Voltage Ratios HIGH", "Unbalanced", "Summation LOW", "Summation HIGH", "Broken/Cracked Solder Joint", "Insufficient Solder", "Missing Solder", "Solder Splatters", "Solder/Wire Peaks", "Soldering Problems", "Flux residue", "Contaminated", "Resistance Wire Damage", "Birdcage", "Cold Solder Connection", "Copper", "Excessive Solder", "Contaminated Connection", "Fractures/Disturbed Connection", "Insulation Damabe", "Overheated Connection", "Overlapping", "Pits, Holes or Voids", "Poor Wetting", "Rosin Connections", "Solder Peaks and Wire Peaks", "Splattering of Flux", "Lead Wire Damage", "Wire Kink", "Magnet Wire Damage", "Oxidation on Resistance Wire", "Uneven Wrap", "Dye Penetrant Inspection Failed", "Dye Penetration Failed", "Friction Test Failed", "Functional Test Failed", "Pressure Leak Failed", "Radiographic (X-Ray) Failed", "Failed Spring Rate Test", "Pressure Test Failed - Air", "Pressure Test Failed - Oil", "Armature Test", "Cracked Weld Joint", "Excessive Weld", "Insufficient Weld", "Welding Voids", "Excessive Inclusions", "Discoloration", "Arc Strike", "Excessive Concavity", "Excessive Splatter", "Insufficient Penetration" });
            }
        }
    }
}

How do I remove the Collection from Settings?

Thanks,
Tim
 
Solution
Do you think that this might be the problem?
C#:
public DefectCollection Defects
{
    get { return FirstPassYield.Properties.Settings.Default.DefectList; }
    set { FirstPassYield.Properties.Settings.Default.DefectList = value; }
}
You are literally telling that property to get and set a value from your application settings. If you don't want that then don't do it. How do you usually write a property that doesn't use an application setting to back it? That's what you need to do here.
Do you think that this might be the problem?
C#:
public DefectCollection Defects
{
    get { return FirstPassYield.Properties.Settings.Default.DefectList; }
    set { FirstPassYield.Properties.Settings.Default.DefectList = value; }
}
You are literally telling that property to get and set a value from your application settings. If you don't want that then don't do it. How do you usually write a property that doesn't use an application setting to back it? That's what you need to do here.
 
Solution
Do you think that this might be the problem?
C#:
public DefectCollection Defects
{
    get { return FirstPassYield.Properties.Settings.Default.DefectList; }
    set { FirstPassYield.Properties.Settings.Default.DefectList = value; }
}
You are literally telling that property to get and set a value from your application settings. If you don't want that then don't do it. How do you usually write a property that doesn't use an application setting to back it? That's what you need to do here.
Thanks. I knew that already. Just not thinking, I guess.
 

Latest posts

Back
Top Bottom