如何从DataGridView中的一行获取DataRow [英] How do I get a DataRow from a row in a DataGridView

查看:1053
本文介绍了如何从DataGridView中的一行获取DataRow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用数据绑定的Windows窗体 DataGridView 。如何从 DataGridView 中的用户选择行转到 DataTable的 DataRow 这是它的来源?

I'm using a databound Windows Forms DataGridView. how do I go from a user selected row in the DataGridView to the DataRow of the DataTable that is its source?

推荐答案

DataRow row = ((DataRowView)DataGridViewRow.DataBoundItem).Row

假设你绑定了一个普通的 DataTable

Assuming you've bound an ordinary DataTable.

MyTypedDataRow row = (MyTypedDataRow)((DataRowView)DataGridViewRow.DataBoundItem).Row

假设您绑定了一个类型的数据。

Assuming you've bound a typed datatable.

有关详细信息,请参阅 MSDN上的文章

See the article on MSDN for more information.

这篇关于如何从DataGridView中的一行获取DataRow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆