首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

请问一个C# Winform的数据邦定有关问题

2012-01-15 
请教一个C# Winform的数据邦定问题在C#Winform中我定义了一个实体格式如下:publicclassUser{string_UserNa

请教一个C# Winform的数据邦定问题
在C#   Winform中   我定义了一个实体   格式如下:
  public   class   User
        {
                string   _UserName,   _Pass;
                IList <string>   _Other   =   new   List <string> ();
                public   string   UserName
                {
                        get   {   return   _UserName;   }
                        set   {   _UserName   =   value;   }
                }
                public   string   Pass
                {
                        get   {   return   _Pass;   }
                        set   {   _Pass   =   value;   }
                }
                public   IList <string>   Other
                {
                        get   {   return   _Other;   }
                        set   {   _Other   =   value;   }
                }
        }

假设Other中有两个值   "男 "   "1985-1-1 "

现在我要把它邦定到DataGridView上并添加UserName、Password、Sex、Brithday列,UserName和Password列DataPropertyName分别为UserName和Password  

Sex我设置了Other[ "Sex "]   结果Sex和Brithday两列都没有显示   请问我怎么设置呢?

[解决办法]
=========================
看看 我的 ..我不想多说了


===
==============================================================================
private List <Gro> groceryList = new List <Gro> ();
private void frmMain_Load(object sender, EventArgs e)
{
Gro[] items = new Gro[]{
new Gro( "Yogurt ",Convert.ToDecimal(2.95)),
new Gro( "Carrots ",Convert.ToDecimal(1.55)),
new Gro( "Celery ",Convert.ToDecimal(0.99)),
new Gro( "Rice ",Convert.ToDecimal(5.39)),
new Gro( "Bread ",Convert.ToDecimal(3.95)),
new Gro( "Milk ",Convert.ToDecimal(3.95)),
new Gro( "Soda ",Convert.ToDecimal(1.99)),
new Gro( "Cheese ",Convert.ToDecimal(5.99)),
new Gro( "Paper Towels ",Convert.ToDecimal(4.55))
};

groceryList.AddRange(items);

UpdateGrid(groceryList);
}
private void UpdateGrid(List <Gro> list)
{
int c=1;
decimal total=0;
dataGridView1.Rows.Clear();
list.ForEach(delegate(Gro item)
{
dataGridView1.Rows.Add(new object[] { c++, item.ITEM, String.Format( "{0:c} ",item.PRICE)});


total += item.PRICE;
});
lblTotal.Text = String.Format( "{0:c} ",total);


}
==
class Gro
{
private string _item = null;
private decimal _price = 0;

public Gro(){}
public Gro(string item, decimal price)
{
_item = item;
_price = price;
}

public string ITEM
{
get { return this._item; }
}

public decimal PRICE
{
get { return this._price; }
}
}
[解决办法]
如果用Eval不行的话
那就只能重新创建一个DataTable
根据Other去动态的创建列,在和原来的正常属性一起绑定到DataGrid

热点排行