Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

Assigning List<T> to a DataGridView.DataSource - data seems to be there, but grid is blank

If you look at the screenshot below, I've got the code stopped just after the assignment of the List<T> to the DataGridView.DataSource.

The DataSource in the Watch window shows a count of 95 items, and if I expand that list, each item has the correct data.

What am I missing?  : /

User generated image
MemParts:

public class MemParts
    {       
        public MemParts() { }

        public void InitMemPartsAsPreview()
        {
            CustID = -1;
            PartNumber = "";
            Description = "";
            TypeID = GlobalDatabaseHelperMethods.GetCellInfo("PartTypes", "PartTypesID", "where Label = 'RAW'", "int").ToString().ExToInt32();
            UMID = GlobalDatabaseHelperMethods.GetCellInfo("UnitMeasureTypes", "UnitMeasureID", "where Label = 'EA'", "int").ToString().ExToInt32();
            ClassID = -1;
            NumberOfLeads = -1;
            CommmonStock = false;
            RoHS = true;
            AllowCrossesID = GlobalDatabaseHelperMethods.GetCellInfo("AllowCrossesTypes", "AllowCrossesID", "where Label = 'APPROVE'", "int").ToString().ExToInt32();
            PackageReqID = -1;
            StatusID = -1;
            Notes = "";
            HasSafetyStock = false;
            ReorderTrigger = 0.00;
            ReorderQnty = 0.00D;
            OtherNotes = "";
        }

        public int CustID = -1;
        public string PartNumber = "";
        public string Description = "";
        public int TypeID = -1;
        public int UMID = -1;
        public int ClassID = -1;
        public int NumberOfLeads = -1;
        public bool CommmonStock = false;
        public bool RoHS = true;
        public int AllowCrossesID = -1;
        public int PackageReqID = -1;
        public int StatusID = -1;
        public string Notes = "";
        public bool HasSafetyStock = false;
        public double ReorderQnty = 0.00D;
        public string OtherNotes = "";
        public double ReorderTrigger = 0.00;
    }//end of class

Open in new window

Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

The issue I believe you are having is that the DataSource of the DataGridView uses the public property of the class and NOT the fields you added. Try the following changes
//  Change this line
public int CustID = -1;

//  To this
public int CustID { get; set; }

Open in new window

Do the same for all the others that follow it.
SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Knowlton

ASKER

There was no issue with auto-generated columns, but something to keep in mind.

Creating properties for the fields did the trick, thank you!


[code]

public class MemParts
    {      
        public MemParts() { }

        public MemParts(int custID, string partNumber, string description, int typeID, int umid, int classID, int numberOfLeads, bool commmonStock, bool rohs, int allowCrossesID, int packageReqID, int statusID, string notes, bool hasSafetyStock, double reorderQnty, string otherNotes, double reorderTrigger)
        {
            CustID = custID;
            PartNumber = partNumber;
            Description = description;
            TypeID = typeID;
            UMID = umid;
            ClassID = classID;
            NumberOfLeads = numberOfLeads;
            CommmonStock = commmonStock;
            RoHS = rohs;
            AllowCrossesID = allowCrossesID;
            PackageReqID = packageReqID;
            StatusID = statusID;
            Notes = notes;
            HasSafetyStock = hasSafetyStock;
            ReorderQnty = reorderQnty;
            OtherNotes = otherNotes;
            ReorderTrigger = reorderTrigger;
        }

        public void InitMemPartsAsPreview()
        {
            CustID = -1;
            PartNumber = "";
            Description = "";
            TypeID = GlobalDatabaseHelperMethods.GetCellInfo("PartTypes", "PartTypesID", "where Label  = 'RAW'", "int").ToString().ExToInt32();
            UMID = GlobalDatabaseHelperMethods.GetCellInfo("UnitMeasureTypes", "UnitMeasureID", "where Label  = 'EA'", "int").ToString().ExToInt32();
            ClassID = -1;
            NumberOfLeads = -1;
            CommmonStock = false;
            RoHS = true;
            AllowCrossesID = GlobalDatabaseHelperMethods.GetCellInfo("AllowCrossesTypes", "AllowCrossesID", "where Label  = 'APPROVE'", "int").ToString().ExToInt32();
            PackageReqID = -1;
            StatusID = -1;
            Notes = "";
            HasSafetyStock = false;
            ReorderTrigger = 0.00;
            ReorderQnty = 0.00D;
            OtherNotes = "";
        }

            private int _custid = -1;
            private string _partnumber = "";
            private string _description = "";
            private int _typeid = -1;
            private int _umid = -1;
            private int _classid = -1;
            private int _numberofleads = -1;
            private bool _commmonstock = false;
            private bool _rohs = true;
            private int _allowcrossesid = -1;
            private int _packagereqid = -1;
            private int _statusid = -1;
            private string _notes = "";
            private bool _hassafetystock = false;
            private double _reorderqnty = 0.00D;
            private string _othernotes = "";
            private double _reordertrigger = 0.00D;

        public int CustID
        {
            get
            {
                return _custid;
            }

            set
            {
                _custid = value;
            }
        }

        public string PartNumber
        {
            get
            {
                return _partnumber;
            }

            set
            {
                _partnumber = value;
            }
        }

        public string Description
        {
            get
            {
                return _description;
            }

            set
            {
                _description = value;
            }
        }

        public int TypeID
        {
            get
            {
                return _typeid;
            }

            set
            {
                _typeid = value;
            }
        }

        public int UMID
        {
            get
            {
                return _umid;
            }

            set
            {
                _umid = value;
            }
        }

        public int ClassID
        {
            get
            {
                return _classid;
            }

            set
            {
                _classid = value;
            }
        }

        public int NumberOfLeads
        {
            get
            {
                return _numberofleads;
            }

            set
            {
                _numberofleads = value;
            }
        }

        public bool CommmonStock
        {
            get
            {
                return _commmonstock;
            }

            set
            {
                _commmonstock = value;
            }
        }

        public bool RoHS
        {
            get
            {
                return _rohs;
            }

            set
            {
                _rohs = value;
            }
        }

        public int AllowCrossesID
        {
            get
            {
                return _allowcrossesid;
            }

            set
            {
                _allowcrossesid = value;
            }
        }

        public int PackageReqID
        {
            get
            {
                return _packagereqid;
            }

            set
            {
                _packagereqid = value;
            }
        }

        public int StatusID
        {
            get
            {
                return _statusid;
            }

            set
            {
                _statusid = value;
            }
        }

        public string Notes
        {
            get
            {
                return _notes;
            }

            set
            {
                _notes = value;
            }
        }

        public bool HasSafetyStock
        {
            get
            {
                return _hassafetystock;
            }

            set
            {
                _hassafetystock = value;
            }
        }

        public double ReorderQnty
        {
            get
            {
                return _reorderqnty;
            }

            set
            {
                _reorderqnty = value;
            }
        }

        public string OtherNotes
        {
            get
            {
                return _othernotes;
            }

            set
            {
                _othernotes = value;
            }
        }

        public double ReorderTrigger
        {
            get
            {
                return _reordertrigger;
            }

            set
            {
                _reordertrigger = value;
            }
        }
    }//end of class

[/code]
Just a note you can do the shorthand if you're not implementing custom logic.