   Finding a Control from a form's binding context[ .NET 2.0 C# ]
  Hi !I am using C# and the .NET framework 2.0.I've been looking online and couldn't find much information or anything clear .I want to know if it is possible to use the BindingContext of a form to retrieve the instance of a control if I can provide it's DataSource and a data member.I cannot access the control directly so it's the reason why I'm looking for alternative to be able to find the instance of the control using the information( from Strings) that I have.[Edited by - Avenyr on September 13, 2007 4:54:45 PM]
  I guess I'm confused why you don't have access to the control directly if you have access to the form?   ;  I do have access to the form, however I must follow the structure that has been set even though I do not totally agree with it. Unless I can find a killer argument to get the project lead to understand that I can and need to pass the controls to the upper layer of functions which are meant to be isolated from any UI/GUI controls to keep it as close to the database as possible and nothing else. It is totally possible but they don't want it that way ... so I'm looking out for other options.   ;  Since restrictions are in place, you should go straight to the source and consult with the project lead on how he wants you to do that.  If he doesn't just give public access to the controls themselves, that means he doesn't want any clever bypassing, either.Now, if you ask him about the problem and he can't figure it out himself then you have a good argument that his design needs some changes -- or you need to rethink your goal from the start and look for alternatives that fit within the current design.  It's a pain, but sometimes it has to be done.   ;  I agree with you Nypyren, I do believe that in some respect the system is flawed. They wanting to use advanced functionality and call delegates and events that will never be used for more than a single function call and such. It's much fun to argue with them but I got to remain polite it's a new job I've had for a month. I don't want them to think I question their ways too much in case it would play against me. I think I'll have to discuss it again with the project lead to see. However he seems hell bent on keeping it the way it is stating that going for a clear simple way would defeat the purpose of the whole structure which makes a bit of sense but still needs some rework. He's the boss he decides !;  Do you have access to the form?  Are you doing the programming of the control?  I have a way that you can kind of hack it if you need to but would be better to get the Lead to explain why you HAVE to do it this way.theTroll   ;  At the level I am I do not have direct access to it but it can pass it to the upper levels if needed. The system is based on 3 layers of abstraction. 1-The Graphical user interface2-A controller Which basically acts as a standard delegate layer where all the basic calls are the same but can be changed at the 3rd layer3- This is what's called the "Logic" Layer where most of the processing is done when gathering data from the database and returning it down the first layer. They are called from the controller layer and usually have the same method name as the controller method names.I am currently working at the 3rd layers So I'd have to pass the form as a parameter or the control needed. I could do that in a complicated, and not so performant way by taking the name of my control or location of a grid and loop through all the controls until I find what I needed back down to the first layer everytime but that's not really optimized is it :P It wouldn't show too much but I'd rather find a cleaner way to do it   ;  Actually if you have access to the form and know the name of the control then getting the control is really easy.Control needed_Control = theForm.Controls.["myControlName"];Hope that helps.theTroll   ;Quote:Original post by TheTrollActually if you have access to the form and know the name of the control then getting the control is really easy.*** Source Snippet Removed ***Hope that helps.theTrollI have already thought and asked about doing so because that's the easiest most convenient way but I was told that would defeat the purpose of the whole layering structure to pass GUI elements to Logics processors.I decided to do a "semi-pass-by" by passing the name of the control as a string and then looking for the control at the form level. It's still not "good" but I was able to convince the project lead that it will do for now until we get some more time to think about it.Thanks for the help and the replies it was helpful.   