Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Child grid navigation
Message
From
19/03/2004 03:12:45
James Hansen
Canyon Country Consulting
Flagstaff, Arizona, United States
 
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
00862807
Message ID:
00887789
Views:
16
I know this thread is a year old, but I found it when I was trying to do almost exactly the same thing and implemented it. I found a problem with this technique and thought I would reply in case somebody else tries to use it.

Using the BindingContext Position only works if the grid is in "natural order". If it is sorted in a different order, say by clicking on a column header, the position passed is the position relative to that order, not the position in the underlying DataSet referenced by the business object. Hence, the wrong record could be referenced in the edit form. (I think it has to do with something about views used in binding, but I'm not deep enough yet to appreciate the details.)

What I did was get the primary key from the Current DataViewRow and pass that:
DataRowView currentDataRow = 
    (DataRowView)this.BindingContext[this.oLogData.GetCurrentDataSet(),
			this.oLogData.TableName].Current;
LogEditForm form = new LogEditForm( this.oLogData, (string)currentDataRow["cID"]);
form.MdiParent = this.MdiParent;
form.Show();
Then in the edit form I scanned the BindingContext Position until I located the primary key:
DataRowView drv;
BindingManagerBase bmb =
    this.BindingContext[oLogDataBizObj.GetCurrentDataSet(),oLogDataBizObj.TableName];
for (bmb.Position=0; bmb.Position<bmb.Count; bmb.Position++)
{
    drv = (DataRowView)bmb.Current;
    if ((string)drv["cID"]==rowID) break;
};
I tried to find a way to tease out the "natural order" record index from a sorted BindingContext, but failed. In the debugger it appears it's there as newRecord or oldRecord, but not accessible in code, near as I can tell. Of course I've only been earnest about .Net for a couple weeks, so I may have missed something.

...Jim Hansen


>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
>
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform