On May 8, 1:15 pm, Bruce Wood <brucew...@cana da.comwrote:
On May 8, 10:16 am, BD <bwald...@chart er.netwrote:
I am coding with C# in Visual Studio 2005 for a database application
residing on remote MS SQL Server 2005. What I want to do is open the
same form but from 2 different places and only one instance. I
currently have the form where it will open from a double click on
datagridview from another form to the proper record and only one
instance. However, doing this bypassed by databinding source for
opening the form to all records. I still want to be able to open the
form to all records again only one instance. I think I need to set
up
custom load methods and run a form load check with if/else statements
pointing the correct load method. I have been unable to do this
however and any help would be greatly appreciated.
Check out the Singleton design pattern. You can apply it to a Form so
that there is only ever one instance of the Form at any given time. It
goes something like this:
public class SingletonForm : System.Windows. Forms.Form
{
private static SingletonForm _instance = null;
private SingletonForm()
{
... usual constructor stuff here ...
}
public SingletonForm Instance
{
get
{
if (SingletonForm. _instance == null)
{
SingletonForm._ instance = new SingletonForm() ;
}
return SingletonForm._ instance;
}
}
}
Then, wherever in your code you need a new SingletonForm, you say
SingletonForm f = SingeltonForm.I nstance;
f.Show();
If there already is one, then it will give it back to you. If there
isn't one, then it will create one.
Of course, you should always use .Show() with this form,
never .ShowDialog(). If the form is already showing and you do
a .ShowDialog(), I have no idea what will happen. (Anyone care to let
us know?)
I need to supply some more information. All of my forms are contained
within MdiParent. On this MdiParent, I have a docked panel with
linklabel to open this form to expose all records. Also have another
linklabel to open another form with datagridview listing showing all
records pertaining to one record. When you doubleclick a row in
datagridview, opens the above form to a specific record. That latter
works fine, but the coding for showing all records is bypassed. See
below:
//The Following is for the LinkLabel Control
private void WorkOrder_Load( object sender, EventArgs e)
{
// TODO: This line of code loads data into the
'datasetWorkOrd ers.Workorder_L abor' table. You can move, or remove it,
as needed.
this.workorder_ LaborTableAdapt er.Fill(this.da tasetWorkOrders .Workorder_Labo r);
// TODO: This line of code loads data into the
'datasetWorkOrd ers.WorkOrderMa terial' table. You can move, or remove
it, as needed.
this.workOrderM aterialTableAda pter.Fill(this. datasetWorkOrde rs.WorkOrderMat erial);
// TODO: This line of code loads data into the
'datasetWorkOrd ers.Locations' table. You can move, or remove it, as
needed.
this.locationsT ableAdapter.Fil l(this.datasetW orkOrders.Locat ions);
// TODO: This line of code loads data into the
'datasetWorkOrd ers.Customers' table. You can move, or remove it, as
needed.
this.customersT ableAdapter.Fil l(this.datasetW orkOrders.Custo mers);
// TODO: This line of code loads data into the
'datasetWorkOrd ers.Work_Order' table. You can move, or remove it, as
needed.
this.work_Order TableAdapter.Fi ll(this.dataset WorkOrders.Work _Order);
}
//The Following is for the Double-Click event on the
datagridrow view on other form
internal void WorkOrder_LoadV iew(int WorkOrderID)
{
work_OrderTable Adapter.FillByW orkOrderID(data setWorkOrders.W ork_Order,
WorkOrderID);
this.workorder_ LaborTableAdapt er.Fill(this.da tasetWorkOrders .Workorder_Labo r);
this.workOrderM aterialTableAda pter.Fill(this. datasetWorkOrde rs.WorkOrderMat erial);
this.locationsT ableAdapter.Fil l(this.datasetW orkOrders.Locat ions);
this.customersT ableAdapter.Fil l(this.datasetW orkOrders.Custo mers);
}