kurt_jackson19

Hi everyone,

I'm a newbie in .net, i have a problem in my application and I hope some could help or gave me an example code regarding with my problem.

My problem is I have two datagrids , the first one is for my Parent/Master data while the second one is for my Child/Detail data. And I have one datasource with an XML file, I could fill the two datagrids , in my Parent/Master datagrid is there's a + sign appear in each rows because thus data has a child.Now what I want to do is hide or disappear the + sign, and Instead the child data should appear to the Child/Detail datagrid.

Problems:

1. How could I hide the + sign in my Parent/Master datagrid rows

2. How could I separate in two datagrid my Parent/Master data and the Child/Detail data

I hope somebody could help to resolve my problems.

Thanks in advance.

regards,

kurt




Re: Windows Forms Data Controls and Databinding Master Detail problems.

pavvu_kk

You seem to have come to a wrong forum. Pls try in C#/VB or .Net forum

Regards,
Pavan
http://pavkul.blogspot.com




Re: Windows Forms Data Controls and Databinding Master Detail problems.

Yu Guo – MSFT

Hi, kurt,

Based on my understanding, you want to seperate the two DataTables into two DataGrids, don't you

I think you are using DataSet to load the XML file. So you should remove the DataRelation to remove the + mark.

And you can use MouseDown event to sync the Data in Parent DataGrid and Child DataGrid.

For example.

Code Block

DataGrid parent;

DataGrid child;

DataView childView;

private void Form1_Load(object sender, EventArgs e)

{

DataSet myset = new DataSet("myset"); //Suppose you read an XML in and there are two tables in it.

myset.ReadXml("xxx.xml");

myset.Relations.Clear(); //Clear the DataRelation to remove the + mark.

parent = new DataGrid();

parent.MouseDown += new MouseEventHandler(parent_MouseDown);

parent.Width = 400;

parent.Height = 150;

parent.DataSource = myset.Tables["table1"];

this.Controls.Add(parent);

childView = myset.Tables["table2"].DefaultView;

childView.RowFilter = "id='" + parent[0, 0].ToString() + "'";

child = new DataGrid();

child.Width = 400;

child.Height = 150;

child.Top = 150;

child.DataSource = childView;

this.Controls.Add(child);

}

void parent_MouseDown(object sender, MouseEventArgs e) //Change the DataSource of Child DataGrid when you change the selection in Parent DataGrid

{

DataGrid.HitTestInfo info = parent.HitTest(e.X, e.Y);

if (info.Type == DataGrid.HitTestType.Cell || info.Type == DataGrid.HitTestType.RowHeader)

{

childView.RowFilter = "id='" + parent[info.Row, 0].ToString() + "'";

}

}

More info

http://msdn2.microsoft.com/en-us/library/system.data.datarelation(VS.80).aspx

Hope this helps,

Regards