EDN Admin
Well-known member
Hi,
I have created a windows form that has one single Datagrid.
That Datagrid displays a parent child relationship between Customer and order table.
I am using VS 2008
SQL SERVER 2005
Database->NORTHWIND sample database.
I am displaying the relationship between the two tables.
<br/>
when I click on the + symbol it shows this
<img src="http://social.microsoft.com/Forums/getfile/37472/" alt="" width="780" height="409
Its shows the name of the relation
When I click on it it displays the order list by that particular customer in a new grid showing only that.
In that grid there is a back button the routes you back to the customer list.
My Question is that
"I want to dispaly the order list of the particular customer click just below it."?
not in a new datagrid but in the same grid without disturbing the other customer record
Also wanted to ask that "Is it possible to display a datagrid in a datagrid"
Heres my current code.<br/>
<div style="color:black; background-color:white
<pre><span style="color:blue using System;
<span style="color:blue using System.Collections.Generic;
<span style="color:blue using System.ComponentModel;
<span style="color:blue using System.Data;
<span style="color:blue using System.Data.Sql;
<span style="color:blue using System.Data.SqlClient;
<span style="color:blue using System.Drawing;
<span style="color:blue using System.Linq;
<span style="color:blue using System.Text;
<span style="color:blue using System.Windows.Forms;
<span style="color:blue namespace DataGrid
{
<span style="color:blue public <span style="color:blue partial <span style="color:blue class Form1 : Form
{
<span style="color:blue string connectionString = <span style="color:blue null;
SqlConnection sqlconnection = <span style="color:blue null;
DataSet ds = <span style="color:blue new DataSet();
<span style="color:blue public Form1()
{
InitializeComponent();
}
<span style="color:blue private <span style="color:blue void Form1_Load(<span style="color:blue object sender, EventArgs e)
{
connectionString=<span style="color:#a31515 "Data Source=WKS-412\sqlexpress;Initial Catalog=Northwind;Integrated Security=True";
sqlconnection=<span style="color:blue new SqlConnection (connectionString);
<span style="color:blue string strCustomers = <span style="color:#a31515 "SELECT * FROM Customers";
<span style="color:blue string strOrders = <span style="color:#a31515 "SELECT * FROM Orders";
<span style="color:green //string strOrderDetails="SELECT * FROM Order Details
SqlDataAdapter da = <span style="color:blue new SqlDataAdapter(strCustomers, sqlconnection);
da.Fill(ds, <span style="color:#a31515 "CustomerTable");
da = <span style="color:blue new SqlDataAdapter(strOrders, sqlconnection);
da.Fill(ds, <span style="color:#a31515 "OrderTable");
<span style="color:green //Creating a relation in the dataset
DataRelation dr = <span style="color:blue new DataRelation(<span style="color:#a31515 "Customer Order List", ds.Tables[<span style="color:#a31515 "CustomerTable"].Columns[<span style="color:#a31515 "CustomerId"],
ds.Tables[<span style="color:#a31515 "OrderTable"].Columns[<span style="color:#a31515 "CustomerId"], <span style="color:blue true);
ds.Relations.Add(dr);
<span style="color:blue this.dataGrid1.DataSource = ds;
<span style="color:blue this.dataGrid1.DataMember = <span style="color:#a31515 "CustomerTable";
}
}
}
[/code]
<br/>
<br/>
<br/>
<br/>
<br/>
View the full article
I have created a windows form that has one single Datagrid.
That Datagrid displays a parent child relationship between Customer and order table.
I am using VS 2008
SQL SERVER 2005
Database->NORTHWIND sample database.
I am displaying the relationship between the two tables.
<br/>
when I click on the + symbol it shows this
<img src="http://social.microsoft.com/Forums/getfile/37472/" alt="" width="780" height="409
Its shows the name of the relation
When I click on it it displays the order list by that particular customer in a new grid showing only that.
In that grid there is a back button the routes you back to the customer list.
My Question is that
"I want to dispaly the order list of the particular customer click just below it."?
not in a new datagrid but in the same grid without disturbing the other customer record
Also wanted to ask that "Is it possible to display a datagrid in a datagrid"
Heres my current code.<br/>
<div style="color:black; background-color:white
<pre><span style="color:blue using System;
<span style="color:blue using System.Collections.Generic;
<span style="color:blue using System.ComponentModel;
<span style="color:blue using System.Data;
<span style="color:blue using System.Data.Sql;
<span style="color:blue using System.Data.SqlClient;
<span style="color:blue using System.Drawing;
<span style="color:blue using System.Linq;
<span style="color:blue using System.Text;
<span style="color:blue using System.Windows.Forms;
<span style="color:blue namespace DataGrid
{
<span style="color:blue public <span style="color:blue partial <span style="color:blue class Form1 : Form
{
<span style="color:blue string connectionString = <span style="color:blue null;
SqlConnection sqlconnection = <span style="color:blue null;
DataSet ds = <span style="color:blue new DataSet();
<span style="color:blue public Form1()
{
InitializeComponent();
}
<span style="color:blue private <span style="color:blue void Form1_Load(<span style="color:blue object sender, EventArgs e)
{
connectionString=<span style="color:#a31515 "Data Source=WKS-412\sqlexpress;Initial Catalog=Northwind;Integrated Security=True";
sqlconnection=<span style="color:blue new SqlConnection (connectionString);
<span style="color:blue string strCustomers = <span style="color:#a31515 "SELECT * FROM Customers";
<span style="color:blue string strOrders = <span style="color:#a31515 "SELECT * FROM Orders";
<span style="color:green //string strOrderDetails="SELECT * FROM Order Details
SqlDataAdapter da = <span style="color:blue new SqlDataAdapter(strCustomers, sqlconnection);
da.Fill(ds, <span style="color:#a31515 "CustomerTable");
da = <span style="color:blue new SqlDataAdapter(strOrders, sqlconnection);
da.Fill(ds, <span style="color:#a31515 "OrderTable");
<span style="color:green //Creating a relation in the dataset
DataRelation dr = <span style="color:blue new DataRelation(<span style="color:#a31515 "Customer Order List", ds.Tables[<span style="color:#a31515 "CustomerTable"].Columns[<span style="color:#a31515 "CustomerId"],
ds.Tables[<span style="color:#a31515 "OrderTable"].Columns[<span style="color:#a31515 "CustomerId"], <span style="color:blue true);
ds.Relations.Add(dr);
<span style="color:blue this.dataGrid1.DataSource = ds;
<span style="color:blue this.dataGrid1.DataMember = <span style="color:#a31515 "CustomerTable";
}
}
}
[/code]
<br/>
<br/>
<br/>
<br/>
<br/>
View the full article