如何将一个对象的成员绑定到数据网格
这是我的问题。我有一个类游戏,我想将一些成员绑定到数据网格,而不是整个对象。有什么更好的方法呢?创建另一个对象来保存信息,或者创建一个数据表?
public class Game
{
public string Name {get;set; }
public string Description {get;set;}
public string FullPath {get;set;}
}
List<Game> Games = new Games { game1, game2, game3 };
dataGrid1.ItemsSource = Game; // I don't want to do this it will bind entire object.
Here is my problem. I have a class game, and i would like to bind some of the members to the datagrid, not entire object. What is better way to do it? Create another object to hold infomation, or create a datatable?
public class Game
{
public string Name {get;set; }
public string Description {get;set;}
public string FullPath {get;set;}
}
List<Game> Games = new Games { game1, game2, game3 };
dataGrid1.ItemsSource = Game; // I don't want to do this it will bind entire object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您仍然可以绑定整个对象、关闭列的自动生成以及手动创建和绑定列。
You can still bind the whole object, turn off automatic generation of columns and create and bind columns manually.
为什么不创建另一个继承游戏类的类。以游戏2为例。然后创建构造函数以仅设置您在游戏一中想要/需要的内容。使用 linq 你可以过滤掉它。
然后您可以将 newData 设置为数据源。请原谅我的任何语法错误。如果你查一下 linq,这是一个非常简单的概念。您甚至不需要继承游戏类。您可以使用所需的信息创建一个名为游戏 2 的独立类。
Why don't you create another class that inherits the game class. Game2 for example. Then create the constructor to only set what you want/need from game one. Using linq you can filter this out.
Then you can set newData as the datasource. Forgive me for any syntax errors. If you look up linq this is a pretty easy concept. You don't need to even inherit the game class. You can create a independent class called game 2 with the info you need.