Answer the question
In order to leave comments, you need to log in
How to organize the interaction of two data entry forms with a third reference form?
Good afternoon.
How to organize interaction between forms? There is an input form (2) and an edit form (1). There is also a 3 form guide. How to organize interaction between forms 1 and 3 and forms 2 and 3.
Code on the forms:
//код с формы 1 событие на двойной клик по полю
private void tbCodeStreet_DoubleClick(object sender, EventArgs e)
{
frmSprStreet form = new frmSprStreet(); //создаем форму населенные пункты
form.btnSelectZero.Visible = true; //Отображаем кнопки "Выбор 0" и "Выбор" на форме населенные пункты
form.btnSelect.Visible = true;
form.ShowDialog(this); //показать модельно форму населенные пункты
}
//код с формы 3 справочника. событие на нажатие по кнопки выбор.
private void btnSelect_Click(object sender, EventArgs e)
{
//написать код для передачи данных из формы населенные пункты на форму вызвашую
frmLScheta frm = this.Owner as frmLScheta;
//frm = this.Owner
frm.tbCodeStreet.Text = dgvStreet.CurrentRow.Cells[0].Value.ToString();
frm.tbStreet.Text = dgvStreet.CurrentRow.Cells[1].Value.ToString();
this.Close();
}
//код с формы 3 справочника. событие на нажатие по кнопки выбор.
private void btnSelectZero_Click(object sender, EventArgs e)
{
//написать код для передачи "пустых данных" из формы населенные пункты на форму вызвашую
frmLScheta frm = this.Owner as frmLScheta;
frm.tbCodeStreet.Text = "";
frm.tbStreet.Text = "";
this.Close();
}
Answer the question
In order to leave comments, you need to log in
by fragments:
1 - here you create a form in a local variable form
and display it as a dialog. modal by the way, but not modal .. if the word confuses , just google the modal window ))
2 and 3 - trick with eliminates ignorance of the variable pointing to the instance of the class. but that's where your
solution problem comes in:
- try treating the main window variables as global to all spawned windows/dialogs. then you can apply another trick - describe in the class of the main window (here apparently ) the form fields of the required types (let 's sayvar frm = this.Owner;
frmLScheta
frmSprStreet SprStreet
). and use them instead of local variables. it will turn out something like
this, but this trick requires a mandatory check on SprStreet for null
- a more classic trick is to create your own constructor for child forms (yes, anything in general), where you can pass both the normally typed value of the main form, and an arbitrarily number of adjacent forms. Naturally, the corresponding typed fields must be provided in the class, where the constructor stores these values (pointers, in essence). checking for null is also required. it can be done in a constructor, but is more reliable in every method where such a pointer is used.
ps
1 - heard the concept of best practices? .. so you have bad practices .. try opening 2 instances of frmSprStreet and working in parallel. well, you'll quickly understand
everything
Understood nothingturns out to be cunning. understood, but not very well. while deleting your comment. and even hang a medal for yourself - a triple slyness. ugh
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question