从gridview到另一个gridview选择一行 [英] Select a row from a gridview to another gridview

查看:67
本文介绍了从gridview到另一个gridview选择一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表,当我选择一个值时,它会在gridview中显示表的内容,但我不知道如何从该gridview中选择一个值到另一个gridview

I have a dropdownlist that when i select a value it displays the content of the table in a gridview but i dont know how to select a value from that gridview to another gridview

推荐答案

这是因为我已经完成了这个,所以

1)这是一般性的指针,而不是一个完整的答案

2)有几乎可以肯定更优雅和/或更有效的方式,然后实际上有一种半自动化的方法,就像第二个DGV过滤器本身基于第一个的一些属性,不能完全记住,几乎当然比我下面的建议更少的代码,但如果它有效...



那么,如果我记得那么......



RowEnter事件有一个EventArgs,可以访问Row和Column索引。

从BindingSource可以获得该索引处的项目及其值等。您可以直接从DGV获取所需的数据好吧,取决于你有哪些领域和你显示的列,iirc。)

然后你可以根据需要在第二个DGV的BindingSource上过滤或查找,改变位置,然后DGV应该改变以反映(或者你可能需要强迫它,不记得了。)



实际上如果你是根据中的值更新第一个DGV一个复选框然后你已经有这种类型的代码启动并运行,只需要用一些小mod修复它。

IIRC,我的问题是试图理解在DGV中发射的事件的顺序和BindingSource,获取wronf,它是错误的行或列或更糟,事件的顺序可能取决于使用鼠标,Tab键或以编程方式更改行,列的简单事情 - 真正令人发狂! br />


Mike
It''s a while since I''ve done this, so
1) This is general pointers rather than a full answer
2) There are almost certainly more elegant and / or efficient ways of doing it, iirc then there is actually a way of semi-automating it, something like having the second DGV filter itself based on some property of the first, can''t remember exactly, almost certainly less code than my suggestion below, but if it works...

So, if I remember then...

The RowEnter event has an EventArgs which gives access to the Row and Column indices.
From the BindingSource you can get the item at that index and it''s values etc. (You may be able to get the data you need directly from the DGV as well, depends what fields you have and what columns you show, iirc.)
Then you can Filter or Find on the BindingSource of the second DGV as required, change Position and then the DGV should change to reflect (or maybe you''ll need to force it to, can''t remember).

In fact if you are updating the first DGV based on the value in a checkbox then you already have this type of code up and running and just need to replicate it with some small mods.
IIRC, my problem was trying to understand the order of events firing in the DGV and the BindingSource, get the wronf one and it''s the wrong row or column or worse, and the order of events can depend on things as simple as using the mouse, the tab key or programmatically changing the row, column - truly maddening!

Mike


这篇关于从gridview到另一个gridview选择一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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