将自定义对象转换为 DataRowView C# WinForms
我有一个自定义对象,如下所示
public partial class _AccessionType
{
private string accessionIdField;
private string docUrlField;
/// <remarks/>
public string AccessionId
{
get
{
return this.accessionIdField;
}
set
{
this.accessionIdField = value;
}
}
public string DocUrl
{
get
{
return docUrlField;
}
set
{
docUrlField = value;
}
}
}
上面的对象用作 DataGridView 的数据源。 我想将上面的对象转换为DataRowView。
我该怎么办?
I have a custom object as follows
public partial class _AccessionType
{
private string accessionIdField;
private string docUrlField;
/// <remarks/>
public string AccessionId
{
get
{
return this.accessionIdField;
}
set
{
this.accessionIdField = value;
}
}
public string DocUrl
{
get
{
return docUrlField;
}
set
{
docUrlField = value;
}
}
}
The above object is used as DataSource for DataGridView.
I want to convert the above object to DataRowView.
How can I do it ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建 _AccessionType 列表并将其分配给网格视图的 DataSource 属性。
在gridView1的设计器中,您需要右键单击> >编辑列并添加绑定列。对于每个绑定列,给出一个合适的 HeaderText,并在 DataField 中分配所需的 _AccessionType 成员属性(例如 DocUrl)
您无法从 gridView.DataSource 检索对象回到 List<_AccessionType> 中。甚至从 GridViewRow 到 _AccessionType。为了获取网格视图行的值,您需要在网格视图中为需要检索的值定义数据键。
例如,
稍后在代码中,您可以在循环访问 DataGrid 或相关数据网格事件处理程序时检索这些值:
You need to create a list of _AccessionType and assign it to the DataSource property of the grid view.
In the designer for gridView1, you need to right click > Edit Columns and add Bound columns. For each bound column give a suitable HeaderText and in the DataField assign the required member property of _AccessionType (e.g. DocUrl)
You cannot retrieve the object from gridView.DataSource back into List<_AccessionType> or even from the GridViewRow into _AccessionType. Inorder to get the values for a grid view row back, you need to define data keys in the grid view for the values you need to retrieve back.
e.g.
Later in the code, you can retrieve back these values when you loop through the DataGrid or in a related data grid event handler: