开发者

get the splitcontainer context in user control click event

开发者 https://www.devze.com 2023-04-08 08:53 出处:网络
Sir, I have a split container in which in right panel i have a usercontrol.In the user control i have few buttons like view,new,edit etc.Bottom of that user control a form will open based on what link

Sir, I have a split container in which in right panel i have a usercontrol.In the user control i have few buttons like view,new,edit etc.Bottom of that user control a form will open based on what link is clicked on the lef开发者_JAVA技巧t side navigation pane. now when i click the user control's view button, i should open a new form below it. how to get the context of splitcontainer in the click event?also if i want to retrieve the form values to save in database when i click the save button in user control, how to do it?


A Click event has a sender parameter, which is the clicked button. You could use the name of the button to resolve which form should be opened.


To get your button in the click event:

Button clickedButton = (Button)sender;

To get the parent of your button (if it was SplitContainer, you'll have to use Parent property 3 times, because the first one will get you your UserControl, second - left panel of the SplitPanel, which doesn't have a Name property, third - your SplitPanel, and 4th, if you want, your form name)

string splitPanemName = clickedButton.Parent.Parent.Parent.Name;

...or you can just get whole SplitPanel object:

SplitPanel currentSplitPanel = (SplitPanel)clickedButton.Parent.Parent.Parent;

...or Form object:

Form currentSplitForm = (Form)clickedButton.Parent.Parent.Parent.Parent;

To do this, you have to be sure of the composition of your Form, so you can get the right controls at the right place.

0

精彩评论

暂无评论...
验证码 换一张
取 消