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.
>int position = this.BindingContext[this.oOrder.GetCurrentDataSet(), this.oOrder.TableName].Position; >>
>Dim position As Integer = Me.BindingContext(Me.oOrder.GetCurrentDataSet(), Me.oOrder.TableName).Position >>
>ChildForm form = new ChildForm(this.oOrder, position); >form.ShowDialog(); >>
>Dim form As New ChildForm(Me.oOrder, position) >form.ShowDialog() >>
>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; >} >>
>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 >>