3 Replies - 372 Views - Last Post: 30 April 2013 - 02:30 AM Rate Topic: -----

#1 Tenderfoot  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 160
  • Joined: 21-March 12

Populating a Datagrid

Posted 30 April 2013 - 01:35 AM

I'm having a problem with populating a DataGrid. I have a class called Phone, which I have bound to a DataGrid in the following way:

        public PhoneView(List<Phone> phoneList)
        {
            InitializeComponent();
            dtaPhoneView.ItemsSource = phoneList;
        }



When I run this, the DataGrid's Item.Count becomes 1, and the list contained one object so that stands to reason. Nothing appears on the DataGrid however. Does anyone see what I'm doing wrong here? I can post more code if needed.

Is This A Good Question/Topic? 0
  • +

Replies To: Populating a Datagrid

#2 Tenderfoot  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 160
  • Joined: 21-March 12

Re: Populating a Datagrid

Posted 30 April 2013 - 01:48 AM

My get and set accessors in the Phone class look like this:

public void setLocation(string location)
        {
            this.location = location;
        }

        public string getPhoneType()
        {
            return this.phoneType;
        }



This might very well be the issue.
Was This Post Helpful? 0
  • +
  • -

#3 Tenderfoot  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 160
  • Joined: 21-March 12

Re: Populating a Datagrid

Posted 30 April 2013 - 02:04 AM

Constructing my accessors like this fixed the problem to an extent:

public int Phone_ID { get; set; }



I now see the object in the DataGrid. The problem is that fields that actually do have a integer value in the phoneList are showing up as zero, all of them.
Was This Post Helpful? 0
  • +
  • -

#4 Tenderfoot  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 160
  • Joined: 21-March 12

Re: Populating a Datagrid

Posted 30 April 2013 - 02:30 AM

Problem fixed:

        public int Phone_ID
        {
            get
            {
                return this.phone_ID;
            }
            set
            {
                this.phone_ID = value;
            }
        }



It was a problem with the get and set accessors, had to set them up like this as I was using private variables.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1