hey you all
i have a main form and there is a button that will open another form as a dialogue, let's call it the AddForm. on the main form i have a DGV and I've written a function to refresh it called DGVreload. it works just fine but i want to call in the AddForm's ExitBtn click event, but i can't since it belongs to the main form and it's not recognized here. can you tell me how to make it known in that form. and i can't make it a static public function.
thanks all

Recommended Answers

All 4 Replies

If you must call it from the AddForm then you'll need to pass a reference to the main form to the AddForm. The easiest way to do this is to create a new constructor in AddForm that takes a mainform parameter and save it.

In general this is a bad practice (there are times you must do this, so it's not *always* bad). This couples the AddForm to the other form and it's possible to break the AddForm code by making changes in the other form. A better method would have you returning something from AddForm that indicates that the main form needs to refresh the DGV.

and how can i return "something" from addform to main form, and what event should i use? i open the addform as a dialog, when it closes, doen't it return something to the main to indicate that it has been closed? can i use that as an event and a trigger for reload function?

well thanks for your time but those links were not very helpful, any ways since i needed the function after i closed the form, i figured out a simple way, i called on the function in a button's click event right after i loaded the child form, lik this:
adduserfrm newuser = new adduserfrm();
thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.