passing Form as refernce to called from dynamically
-
hi, i m new to Visual Studio 2005 and i m developing a windows application in c#. I m facing a problem in which i have to pass reference of the calling form (frmCityMaster.cs) to called form (frmList.cs). The form frmList.cs has a datagrid control (dgList) which displays all the data of the table citymaster, and the form frmCityMaster has a int variable iMasterId and a method EDITMASTER() to load all the data about a city for editing purpose based upon the variable of the variable iMasterId. COnsider the following programming case, i want to pass the reference of the calling form (frmCityMaster) to the called form (frmListMaster) so that i m able to set the variable iMasterId value with the city selected in the row of the datagrid (dgList) on frmList.cs... And also i want to call the method EDITMASTER() on frmCity.cs from form frmList.cs... The above presented problem is just one of the n possiblilities that may occur and this i know can be easily solved by passing the reference of the form frmCityMaster.cs to the calling form frmList.cs but my question is what if the calling forms are dynamic i.e. the calling forms can be any from say frmCityMaster.cs, frmStateMaster.cs or say frmCountryMaster.cs each having a iMasterId as an integer variable to hold the PRIMARY KEY value of the current row from database table and EDITMASTER() method to fill the form controls with the current database master record based the current iMasterId value. And now that i want to pass the reference of the calling form say frmCityMaster.cs or frmStateMaster.cs to called form (frmList.cs) form so as to be able initialise the calling form's iMasterId variable and EDITMASTER() to initialise the current PRIMARY KEY values. How can i achieve this using C# Visual Studio 2005. My database server is SQL Server. abhinav
-
hi, i m new to Visual Studio 2005 and i m developing a windows application in c#. I m facing a problem in which i have to pass reference of the calling form (frmCityMaster.cs) to called form (frmList.cs). The form frmList.cs has a datagrid control (dgList) which displays all the data of the table citymaster, and the form frmCityMaster has a int variable iMasterId and a method EDITMASTER() to load all the data about a city for editing purpose based upon the variable of the variable iMasterId. COnsider the following programming case, i want to pass the reference of the calling form (frmCityMaster) to the called form (frmListMaster) so that i m able to set the variable iMasterId value with the city selected in the row of the datagrid (dgList) on frmList.cs... And also i want to call the method EDITMASTER() on frmCity.cs from form frmList.cs... The above presented problem is just one of the n possiblilities that may occur and this i know can be easily solved by passing the reference of the form frmCityMaster.cs to the calling form frmList.cs but my question is what if the calling forms are dynamic i.e. the calling forms can be any from say frmCityMaster.cs, frmStateMaster.cs or say frmCountryMaster.cs each having a iMasterId as an integer variable to hold the PRIMARY KEY value of the current row from database table and EDITMASTER() method to fill the form controls with the current database master record based the current iMasterId value. And now that i want to pass the reference of the calling form say frmCityMaster.cs or frmStateMaster.cs to called form (frmList.cs) form so as to be able initialise the calling form's iMasterId variable and EDITMASTER() to initialise the current PRIMARY KEY values. How can i achieve this using C# Visual Studio 2005. My database server is SQL Server. abhinav
abhinish wrote:
i have to pass reference of the calling form (frmCityMaster.cs) to called form (frmList.cs).
No you don't. http://en.wikipedia.org/wiki/Object-oriented_programming[^] You can use things like encapsulation, interfaces and software design patterns to make the appropriate information available accross different forms or anything else. led mike
-
hi, i m new to Visual Studio 2005 and i m developing a windows application in c#. I m facing a problem in which i have to pass reference of the calling form (frmCityMaster.cs) to called form (frmList.cs). The form frmList.cs has a datagrid control (dgList) which displays all the data of the table citymaster, and the form frmCityMaster has a int variable iMasterId and a method EDITMASTER() to load all the data about a city for editing purpose based upon the variable of the variable iMasterId. COnsider the following programming case, i want to pass the reference of the calling form (frmCityMaster) to the called form (frmListMaster) so that i m able to set the variable iMasterId value with the city selected in the row of the datagrid (dgList) on frmList.cs... And also i want to call the method EDITMASTER() on frmCity.cs from form frmList.cs... The above presented problem is just one of the n possiblilities that may occur and this i know can be easily solved by passing the reference of the form frmCityMaster.cs to the calling form frmList.cs but my question is what if the calling forms are dynamic i.e. the calling forms can be any from say frmCityMaster.cs, frmStateMaster.cs or say frmCountryMaster.cs each having a iMasterId as an integer variable to hold the PRIMARY KEY value of the current row from database table and EDITMASTER() method to fill the form controls with the current database master record based the current iMasterId value. And now that i want to pass the reference of the calling form say frmCityMaster.cs or frmStateMaster.cs to called form (frmList.cs) form so as to be able initialise the calling form's iMasterId variable and EDITMASTER() to initialise the current PRIMARY KEY values. How can i achieve this using C# Visual Studio 2005. My database server is SQL Server. abhinav
Since all of the "calling" forms have a field called iMasterId and the EDITMASTER method (why all caps??) you could create a base form which all of the calling forms derive. That base form would contain those two members. But that's really weird. What you probably should do is have the "calling" form initialize itself, instead of passing itself to another form to be initialized. The initialization details of the form should not be known by other forms, that's bad OOP. In the future, it would be much easier for people to understand your question if you were to leave out a lot of irrelevant details. For example, if the controls on a form and the names of those controls is not relevant to the question, there's no need to mention them. :) Josh