如何通过数据表中的行索引在datagridview中找到对应的行? [英] How to find the corresponding row in a datagridview by the row index in a datatable?

查看:277
本文介绍了如何通过数据表中的行索引在datagridview中找到对应的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为dgv1的datagridview,它的数据源是一个名为dt1的数据表.对于同一数据行,在对dgv1进行某些操作(例如排序)后,dt1中的行索引可能与dgv1中的行索引不同.现在,我在dt1中有一行索引,我想在dgv1中找到它的对应行.除了在dgv1中搜索数据行的值之外,是否还有其他方法?

I have a datagridview named dgv1, and it''s datasource is a datatable named dt1. For the same data row, the row index in dt1 may be different from the row index in dgv1 after some operation on dgv1, for example sorting. Now, I have one row''s index in dt1, and I want to find it''s corresponding row in dgv1. Is there any method other than searching data row''s value in dgv1?

推荐答案

要做的简单操作是将项目直接广播为类项目.这样,您就不必担心索引的放置....但是,您可以在可枚举集合中使用IndexOf来获取已投射项目的索引.
The simpe thing to do is to directcast the items as your class item. That way you shouldnt need to worry about the index placing.... You can however use the IndexOf in the enummarable collection to get the index of your casted item.


这篇关于如何通过数据表中的行索引在datagridview中找到对应的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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