开发者

DataBinding to GridView

开发者 https://www.devze.com 2022-12-29 09:00 出处:网络
I Have a gridview object and I want to bind it to an Object. My Object is public class BindingObject { public ColorInfo Color { get; set; }

I Have a gridview object and I want to bind it to an Object.

My Object is

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; }
    }
}

I want that in the gridview I will see only the properties Name and Red Now when I bound it my gridview see like this: Color an开发者_开发百科d Name, but I want Red and Name.

How can I do this?

Thanks.

Update: Thanks, but if I want to add a property setter

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

I get this error:

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

Thank you for the fast reply


Change ColorInfo from struct to class or use fields in this struct instead of properties.

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


Red,Green,Blue all are key words, please avoid to use key words

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号