datagrid with nested dataset

  • Thread starter Thread starter suzy
  • Start date Start date
S

suzy

im building a datagrid control at runtime using a dataset as the datasource
and everything was working fine.

i then needed to change my dataset to be nested data and now i don't know
how to set the DataField property of child values in the dataset.

can anyone help me please?!

thanks.
 
Suzy,

Unless someone else answers this, repost with a bit more information.
Specifically, what your DataSet looks like in terms of its tables and
relations.

The short answer is to set the tables and relations and bind to the DataSet,
letting the datagrid take care of the rest (assuming Windows.Forms)
 
hi kath

my dataset contains 2 tables, customers and orders. one of the columns in
EACH table is called customerid which is a primary key in one table, and a
foreign key in the other table.

i create a dataset relation between these 2 fields, then set the
dataset.nested property to true to create a hierarchy.

my problem arises when i try to read the values from the dataset in order to
populate a datagrid. i can read the top level table by simply assigning the
name of the column to the datafield property of the datagrid.

but this doesn't work for the child table. i thought this would be a common
problem but i cant find the answer on the net. !!
 
Suzy,
Do you need the DataGrid to display the data in nested
format or just the second table. If the latter then Bind
the DataGrid to your Orders table rather than directly to
the DataSet. ie

myDataGrid.DataSource = myDataSet.Tables["Orders"];

Hope this helps.

Dave
 
David,

i need to retrieve data from both tables, but the data does not need to be
displayed in a nested fashion.

for some reason i can read the values from the orders table, but it doesnt
work for the customers table (which is nested).

any ideas?
 
Suzy,

Are you sure that both Tables have been filled? Try
DataSet.Tables.Count to check that both Tables are
present. Then check that both Tables have data in them
using
DataSet.Tables[0].Rows.Count and
DataSet.Tables[1].Rows.Count

Providing that both Tables have data then you should be
able to display them by binding your DataGrid directly to
the Tables one at a time rather than to the DataSet by
setting the DataGrids DataSource to the Table.

i.e. if you have a DataGrid called myGrid and a DataSet
called myDS then do:

myGrid.DataSource = myDS.Tables[0];

to display the first Table and then use

myGrid.DataSource = myDS.Tables[1];

to display the second Table.

Hope this helps, if you still have problems then try
posting some code.

Regards,

Dave
 
Suzy,

I'm not in the office this week so can't check your
code. One thing to try would be to replace

oDatagrid.DataSource = oDataSet;

with

oDatagrid.DataSource = oDataSet.Tables[1];

when you try to bind to your customer data.

If you're still having problems I'll have a look when I
get home.

Dave
 
Back
Top