2010-05-08 83 views
0

我有一個gridview對象,我想將它綁定到一個對象。DataBinding GridView

我的對象是

public class BindingObject 
{ 
    public ColorInfo Color { get; set; } 
    public string Name { get; set; } 

    public struct ColorInfo 
    { 
     public string Red { get; set; } 
     public string Green { get; set; } 
     public string Blue { get; set; } 
    } 
} 

我想,在GridView中,我將只看到屬性NameRed 現在,當我勢必是我的GridView中看到這樣的:ColorName,但我想RedName

我該怎麼做?

謝謝。

更新:謝謝你,但是如果我想添加一個屬性的setter

public string Red { 
    get { return this.Color.Red; } 
    set { this.Color.Red = value; } 
} 

我得到這個錯誤:

Error 1 Cannot modify the return value of 'DataBinding.BindingObject.Color' because it is not a variable

謝謝你的快速回復

+0

ASP .NET或WinForms的GridView的?有很大的不同。 – driis 2010-05-08 11:22:30

回答

0

更改彩光電從結構到類或使用此結構中的字段而不是屬性。

public struct ColorInfo 
    { 
     public string Red; 
     public string Green; 
     public string Blue; 
    } 
0

紅,綠,藍都是關鍵的話,請儘量避免使用關鍵詞