Hi Michael,
Question 1:
Yes, you are right. DataGridView doesn't support the function to show
hierarchical data in one DataGridView control. But we could do this with
two DataGridViews. One DataGridView shows data in the parent DataTable and
the other shows the corresponding data in the child DataTable.
Below is a walkthrough.
1. Set up a WinForms application. Ceate a DataSet in the project, add two
DataTables into the DataSet,i.e parentTable and childTable and set up a
relationship between the DataTables, i.e relation1.
2. Add an instance of the DataSet, i.e dataset1, two BindingSource
instances , i.e parentBindingSo urce and childBindingSou rce, and two
DataGridViews, i.e parentDataGridV iew and childDataGridVi ew onto your form.
3. Use the following code to bind the two BindingSources and two
DataGridViews.
this.parentBind ingSource.DataS ource = this.dataset1;
this.parentBind ingSource.DataM ember = "parentTabl e";
this.childBindi ngSource.DataSo urce = this.parentBind ingSource;
this.childBindi ngSource.DataMe mber = "relation1" ;
this.parentData GridView.DataSo urce = this.parentBind ingSource;
this.childDataG ridView.DataSou rce = this.childBindi ngSource;
Thus, when the program is running, the parentDataGridV iew shows the data in
the parentTable and the childDataGridVi ew shows the corresponding data in
the childTable.
Question 2:
To display the XML elements that are at different hierarchical levels as
columns, I recommend you to separate these XML elements into two DataTables
and use two DataGridViews to display the data in the two DataTables
respectively.
Question 3:
I recommend you to add a XML schema file into the project to define the
computed column in the schema file. I will take the project in the
following link for example to demonstrate how to do this.
http://msdn.microsoft.com/library/de...us/vbcon/html/
vbwlkWalkthroug hAccessingXMLDa ta.asp
When you running the sample program in the above link and click on the
"show schema" button, the XML schema information is displayed in the
textbox1. To add a computed element in the XML file, you could add an XML
Schema file into the project, clear the content in this schema file and
copy the content in the textbox1 to this file. Then you could add a
computed element in the schema file like below.
<xs:element name ="computedcolum n" type ="xs:int" msdata:Expressi on =
"len(au_fna me)"/>
In the btnReadXML's click event handler, you add the following code before
"dsAuthors.Read Xml(filePath);" :
dsAuthors.ReadX mlSchema("Compl ete path where you saved the XML Schema
file");
Thus, the computed element will displayed in the DataGridView when the
program is running.
For more information on the expression of computed column, you may refer to
" The Syntax of Expressions" section in the following link:
http://msdn.microsoft.com/library/de...us/dndive/html
/data05312002.as p
Hope this helps.
If you have anything unclear, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.