0

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?

Community
  • 1
  • 1
Thorin
  • 27
  • 7

2 Answers2

0

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 :)

Peter
  • 1
  • 1
0

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);
}
Community
  • 1
  • 1
nempoBu4
  • 6,521
  • 8
  • 35
  • 40