By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,152 Members | 1,837 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,152 IT Pros & Developers. It's quick & easy.

How to access Child table data within a windows form datagrid

P: n/a

Hi All,

I am trying to acess the rows within a child table of a windows form
datagrid. I have tried using the CurrencyManager & BindingManagerBase
to get the data but doesn't work.

The problem is that when trying to retrive a row from a childtable in a
datagrid using either objects it still retrieves the parents data. I
want the selected childtable row data.

My XML:
<Customers id="123" name="Joe" level="A">
<Orders id="1234" date="2004-04-02" level="A"/>
<Orders id="1236" date="2004-04-02" level="B"/>
<Orders id="1233" date="2004-04-02" level="C"/>
</customers>
<Customers id="098" name="Mike" level="A">
<Orders id="1274" date="2004-04-02" level="A"/>
<Orders id="1276" date="2004-04-02" level="B"/>
<Orders id="1203" date="2004-04-02" level="C"/>
</customers>
<Customers id="757" name="Pat" level="A">
<Orders id="1433" date="2004-04-02" level="A"/>
<Orders id="1432" date="2004-04-02" level="B"/>
<Orders id="1421" date="2004-04-02" level="C"/>
</customers>

The dataset is directly populated with the XML.
No Datarelations are manually created.

DataView view = _ds.Tables[ "Customers" ].DefaultView;

foreach(DataTable dTable in _ds.Tables)
{
DataGridTableStyle dgStyle = new DataGridTableStyle();
dgStyle.MappingName = dTable.TableName;
dataGrid1.TableStyles.Add(dgStyle);
dataGrid1.TableStyles[ dTable.TableName ].AllowSorting = false;
}

dataGrid1.DataSource = view;

CurrencyManager _cm =
(CurrencyManager)BindingContext[dataGrid1.DataSource,
dataGrid1.DataMember];
BindingManagerBase _bm = BindingContext[dataGrid1.DataSource,
dataGrid1.DataMember];
The code in a buttonclick event.
It is suppose to get the orders ID & Level, but it gets the parents
instead. :(

//Using BindingManagerBase
string selectedCustomer =
((DataRowView)_bm.Current).Row["level"].ToString();
string selectedID = ((DataRowView)_bm.Current).Row["id"].ToString();

//Using CurrencyManager

DataRowView dr = (DataRowView)_cm.Current;
string selectedCustomer = dr["level"].ToString();
string selectedID = dr["id"].ToString();
Any help?

Lanky

Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.