使用Bindinglist在datagridview中显示右数据表

时间:2011-05-10 19:46:47

标签: c# datagridview bindinglist

目标:

  

显示播放器的封装字段

问题:
想要仅使用datamember_id

在课程_name中显示_bustmainformbindingList

是否假设在封装字段上方使用语法[]


Class MainForm

    dataGridViewPlayers.AutoGenerateColumns=true;
    dataGridViewPlayers.AutoSizeColumnsMode=DataGridViewAutoSizeColumnsMode.Fill;

    bindingSourcePlayers.Clear();

    bindingSourcePlayers.DataSource = _myGameManager.Players;




Class GameManager:

    public BindingList<Player> Players
    {
        get
        {
            for (int i = 0; i < _myPlayerGUI_list.Count; i++)
            {
                _player.Add(new Player(_myPlayerGUI_list[i].Player));
            }
            return _player;
        }

    }

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CardGameClassLibrary;

namespace CardGameLib
{
    public class Player
    {

        private int _id;
        private string _name;
        private Hand _myHand;
        private int _win;
        private int _lost;
        private bool _madeMove = false;
        private bool _bust = false;


        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public Hand MyHand
        {
            get { return _myHand; }
            set { _myHand = value; }
        }

        public int Win
        {
            get { return _win; }
            set { _win = value; }
        }

        public int Lost
        {
            get { return _lost; }
            set { _lost = value; }
        }

        public bool MadeMove
        {
            get { return _madeMove; }
            set { _madeMove = value; }
        }

        public bool Bust
        {
            get { return _bust; }
            set { _bust = value; }
        }

        public Player(int pId)
        {
            _id = pId;

            _myHand = new Hand();
        }


        public Player(Player pPlayer)
        {
            _id = pPlayer.Id;
            //_name = pPlayer.Name;
            _name = "adsf";
        }


        public Player()
        {

        }



    }
}

1 个答案:

答案 0 :(得分:1)

您可以使用Browsable()属性来阻止在使用DataGridViewBindingList中显示特定属性。

示例:如果要隐藏MadeMove

[Browsable(false)]
public bool MadeMove
{
    get { return _madeMove; }
    set { _madeMove = value; }
}