Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Child grid navigation
Message
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
00862807
Message ID:
00863023
Vues:
17
>Sorry for the silly question, but how do you pass the binding context position to the child form and what do you do with it? Do I put another business object on the child form to deal with the single record?

Not at all...the whole Windows data binding structure is somewhat complex!

If you want to reference the object on the parent form from the child form, you can do the following:

1. Within the parent form, get the binding context for the business object's associated DataSet and table. For example (where this.oOrder contains a reference to an "Orders" business object):

In C#
int position = this.BindingContext[this.oOrder.GetCurrentDataSet(), this.oOrder.TableName].Position;
In VB .NET:
Dim position As Integer = Me.BindingContext(Me.oOrder.GetCurrentDataSet(), Me.oOrder.TableName).Position
2. You can then pass the business object and position to the child form. For example:

In C#:
ChildForm form = new ChildForm(this.oOrder, position);
form.ShowDialog();
In VB .NET:
Dim form As New ChildForm(Me.oOrder, position)
form.ShowDialog()
3. In the constructor of the child form, you can register the passed business object, issue BindAllControls(), and then set the specified position.

In C#:
public ChildForm(Orders orders, int position)
{
	// Register the orders business object
	this.RegisterBizObj(orders);
	//
	// Required for Windows Form Designer support
	//
	InitializeComponent();

	// Bind all user interface controls
	this.BindAllControls();

	// Set the position to that of the parent form
	this.BindingContext[orders.GetCurrentDataSet(),orders.TableName].Position = position;
}
In VB .NET:
Public Sub New(orders As Orders, position As Integer)
      ' Register the orders business object
      Me.RegisterBizObj(orders)
      '
      ' Required for Windows Form Designer support
      '
      InitializeComponent()
      
      ' Bind all user interface controls
      Me.BindAllControls()
      
      ' Set the position to that of the parent form
      Me.BindingContext(orders.GetCurrentDataSet(), orders.TableName).Position = position
End Sub
Alternately, you could simply put a new instance of the Orders business object on the child form and retrieve the current row when the form instantiates. When working with am MM .NET DataGrid on the parent form, (as you pointed out) you can get the PK of the current row by means of the DataGrid's GetCurrentRowPK() method. You could pass this as a parameter to the child form.

Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform