as seen in this post, I need to interact with the button, I mean, save the value of the repository when the user press the OK button, any suggest?
-
I don't understand why you just don't use event EditValueChanged – HubertL Sep 05 '15 at 00:21
-
Do you only want to do it on the pressing of the button or when any value changes, like when the user uses the keyboard? – Scott Wylie Sep 05 '15 at 01:07
-
I need to do it only with the button. – Thorin Sep 07 '15 at 16:25
2 Answers
I think you can use object sender. sender will contains probably TimeSpanEditDropDownForm and there you should get actual value of this form. :) I presume this code is called from controller is it?
if it is true than you have View.CurrentObject and you must know which property uses this TimeSpanEditDropDownForm so you could do something like this.
private void OkButton_Click(object sender, EventArgs e)
{
MyClass myClass = View.CUrrentObject as MyClass;
TimeSpanEditDropDownForm timeSpanForm = sender as TimeSpanEditDropDownForm;
myClass.CurrentTime = timeSpanForm.CurrentTime;
myClass.Session.CommitChanges();
MessageBox.Show("Ok");
}
I dont know what is name of right attribute wich store TimeSpan inside TimeSpanEditDropDownForm thats thing you must find out but I think it could helps :)

- 1
- 1
You need to find your TimeSpanEdit
control inside of the popup form. You can iterate through popupForm.Controls
collection to find out the control with TimeSpanEdit
type. Here is example of how to do it. After that you can use TimeSpanEdit.TimeSpan
property to get the value of TimeSpanEdit
control.
private void OkButton_Click(object sender, EventArgs e)
{
var popupForm = (TimeSpanEditDropDownForm)OwnedForms.FirstOrDefault(item => item is TimeSpanEditDropDownForm);
if (popupForm == null)
return;
var timeSpanEdit = GetAll(this, typeof(TimeSpanEdit)).FirstOrDefault();
if (timeSpanEdit == null)
return;
MessageBox.Show(timeSpanEdit.TimeSpan.ToString());
}
public IEnumerable<Control> GetAll(Control control,Type type)
{
var controls = control.Controls.Cast<Control>();
return controls.SelectMany(ctrl => GetAll(ctrl,type))
.Concat(controls)
.Where(c => c.GetType() == type);
}