c# - Display right datamember in the datagridview by using Bindinglist -
goal:
display encapsulate field player
problem:
want display datamember_id
, _name
, _bust
in class mainform
using bindinglist
was suppose use syntax []
above encapsulate field?
class mainform datagridviewplayers.autogeneratecolumns=true; datagridviewplayers.autosizecolumnsmode=datagridviewautosizecolumnsmode.fill; bindingsourceplayers.clear(); bindingsourceplayers.datasource = _mygamemanager.players; class gamemanager: public bindinglist<player> players { { (int = 0; < _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 { { return _id; } set { _id = value; } } public string name { { return _name; } set { _name = value; } } public hand myhand { { return _myhand; } set { _myhand = value; } } public int win { { return _win; } set { _win = value; } } public int lost { { return _lost; } set { _lost = value; } } public bool mademove { { return _mademove; } set { _mademove = value; } } public bool bust { { 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() { } } }
you can use browsable() attribute prevent specific properties being shown in datagridview
when usin bindinglist
.
example: if want hide mademove
:
[browsable(false)] public bool mademove { { return _mademove; } set { _mademove = value; } }
Comments
Post a Comment