473,385 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Parent-Child Relation in DataGrid

I have a data grid called Files, which has some columns like FileName, Col1,
Col2, ... , Col8. Then i have a combobox which allows user to select from
Col1 to Col8 and based on this selection, i generate a report from data in
grid Files.
It displays like (e.g. is Col1 is selected):
Col1 Count
----------------------
Val1 x
Val2 y
.....

This data i display in another datagrid called Data. And under each row in
this grid, i want to show related records. So, when i expand row with Val1,
all rows from Files grid which has Val1 as value for Col1 should be displayed.
To achieve this, i created relation between first column (or selected
column, i.e. Col1 here) of the 'Data' grid and the selected column (e.g. Col1
here) of 'Files' grid. Here is the code for the same:
tblData.DataSet.Relations.Add("Details",tblData.Co lumns[cat],tblFiles.Columns[cat])

This works perfectly. Now, the problem is when i change selection in
comboxbox to say Col2 and try to recreate the rows in the 'Data' grid, it
fails.
I used clear method on datatable for it to clear rows, but it gives foreign
key constraint violation says child table has records in it.
So, i tried removing the relation while recreating the datatable by doing:
tblData.DataSet.Relations.Clear()

Doing this, The watch window shows me that relationship is removed, but
still i get the same error. I tried clearing ChildRelations and
ParentRelations as well for the datatable but of no use.
Q1. Am i missing something here? What else i need to do to remove a
relationship?

I did a workaround for this by setting tblData.DataSet.EnforceConstraints =
false. It did the work but I am still clueless how can i remove a
relationship?

-----------------------

This is not all... I have some more problems after doing this workaround.. :-(
Now after recreating the 'Data' table, it correctly shows report on the
selected column. And to create different relation now, i do following:
tblData.DataSet.Relations.Clear();
tblData.DataSet.Relations.Add("Details",tblData.Co lumns[cat],tblFiles.Columns[cat]);

However, when i expand one of the rows to see its child rows, it still
refers to old relation. e.g. Now i select Col2 from dropdown, it displays
'Data' as:
Col2 Count
----------------------
Val1 x
Val2 y
.....

If i expand row with Val1, it still shows rows from Files table which has
Val1 as value of Col1 and NOT Col2. Basically last created relationship is
maintained.

I could do a workaround for this as well, by adding everytime relationship
with a new name. So, instead of doing this:
tblData.DataSet.Relations.Add("Details",tblData.Co lumns[cat],tblFiles.Columns[cat]);
i do now:
tblData.DataSet.Relations.Add(cat + "
Details",tblData.Columns[cat],tblFiles.Columns[cat]);

Q2. It works perfectly fine now, but still no idea what is wrong with
original code.

----------------------

Bear with me... There is one more problem now, last one... :-(
Q3. Now on expanding the child rows, i want to get the selected child row.
How to get the selected child row? I am able to find the selected parent row
but have no idea what should be done to get selected child row. Please help.
Thanks for your patience,
Ambica

May 23 '06 #1
0 2881

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Suzanne Vogel | last post by:
Hi, Given: I have a class with protected or private data members, some of them without accessor methods. It's someone else's class, so I can't change it. (eg, I can't add accessor methods to the...
5
by: Zürcher See | last post by:
The Control class has the Parent property that is readonly. When the control is added to a controls collection of another control the Parent property refers to that control. "Who" set the Parent...
2
by: Jeronimo Bertran | last post by:
Hi, I have a page with a very data intensive grid which needs to be automatically refreshed constantly if a change is detected. In order to not refresh the complete page so often, I created an...
4
by: Phil Powell | last post by:
I thought this would work but it seems to not work neither in Netscape nor in IE: <script type="text/javascript"> <!-- // OBTAINED FROM http://www.javascripter.net/faq/settinga.htm //...
6
by: Ray Schumacher | last post by:
What is the feeling on using "parent" in a class definition that class methods can refer to, vs. some other organization ? Should all relevant objects/vars just be passed into the method as needed?...
2
by: Steven | last post by:
I have a page(pg1) which contains a select list (list1) in a form(form1) and an iframe(frame1), in this iframe is a page(pg2) with another select list(list2) in a form(form2) and I transfer the...
1
by: IframeLearner | last post by:
Hi , I am trying to upload a file from a parent.jsp using Iframes. From Parent page. I have to save Subject, Desc, File and file name. to upload the file i am using Iframe. I want the...
5
by: gnewsgroup | last post by:
In my user control, I would like to find a Label control in the parent page (the page that uses my user control). I need to update that Label.Text when something happens in the user control. I...
1
by: bnchs | last post by:
This is C code. I am trying to fill each node's Parent field with its parent because I am drawing nodes to the screen. However, I have not been able to get this working. Reading the output from the...
4
by: Andrew | last post by:
I want to create a set of Activity Diagram controls for process control. I need to create a base Diagram control that acts as a container for the Activity controls ( StartPoint, EndPoint,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.