Position on datagrid v position in dataset

I am new to VB Express 2005 (convert (possibly) from Delphi) and I am trying to do something quite simple.

I have a datagridview bound to a dataset - no problem so far, the grid shows exactly what I expect.

On double click, I want to load another form to show the detail of the currently selected row. I do this by setting the new form's bindingsource datasource and position to be that of the calling form.

This works fine until I sort the grid - I then get the wrong record. I get the nth record in the dataset whereas I want the record shown on the nth row of the grid.

I sure this has something to do with binding contexts and currency managers but at the moment my brain is hurting and I haven't found a really clear and simple explanation.

Calling code is as follows:


PrivateSub StocksDataGridView_DoubleClick(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles StocksDataGridView.DoubleClick

Dim fAsNew Form_Detail

f.StocksBindingSource.DataSource = ShareMonitorDataSet

f.StocksBindingSource.Position = StocksBindingSource.Position

f.ShowDialog()

EndSub




I would really appreciate some help.

Liz

[2683 byte] By [fishpond777] at [2007-12-16]
# 1
Hello Liz,

Instead of setting the detail based on position you might try using the BindingSource.Current property. This gives you the actual record you are on.

in the double-click you can use code like this to get the actual datarow from the selected row in the DataGridView:

Dim SelectedRowView As Data.DataRowView = CustomersBindingSource.Current
Dim SelectedRow As NorthwindDataSet.CustomersRow = CType(SelectedRowView.Row, NorthwindDataSet.CustomersRow)
This topic shows one way to display related records in a second form:

Walkthrough: Passing Data between Windows Forms
http://msdn2.microsoft.com/library/ms171925(en-us,vs.80).aspx
hope this helps...

SteveS_MS at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 2
Thanks Steve - very helpful.
fishpond777 at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...