Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 23-Mar-13 4:56am
v2
Comments
Sandeep Mewara 23-Mar-13 14:27pm    
Web app? Tag says winform, is so?

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900