This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
70 lines (63 loc) · 2.47 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
namespace Sample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
customersTableAdapter1.Fill(nwindDataSet1.Customers );
ordersTableAdapter1.Fill(nwindDataSet1.Orders );
GridView masterGridView = new GridView();
GridView detailView = new GridView();
GridLevelNode gridLevelNode2 = new GridLevelNode();
gridLevelNode2.LevelTemplate = detailView;
gridLevelNode2.RelationName = "CustomersOrders";
GridControl gridControl = new GridControl();
detailView.DataSourceChanged += new EventHandler(detailView_DataSourceChanged);
detailView.GridControl = gridControl;
gridControl.ViewCollection.Add(masterGridView);
gridControl.LevelTree.Nodes.Add(gridLevelNode2);
gridControl.MainView = masterGridView;
gridControl.DataSource = nwindDataSet1.Customers;
Controls.Add(gridControl);
gridControl.Dock = DockStyle.Top;
masterGridView.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(masterGridView_FocusedRowChanged);
}
void detailView_DataSourceChanged(object sender, EventArgs e)
{
dataGrid.DataSource = null;
dataGrid.DataMember = "";
GridView gv = sender as GridView;
if (gv == null) return;
dataGrid.DataSource = gv.DataSource;
}
void masterGridView_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
GridView gv = sender as GridView;
dataGrid.DataSource = null;
GridView detailView = gv.GetDetailView(e.FocusedRowHandle, 0) as GridView;
if (detailView == null)
{
dataGrid.DataMember = "CustomersOrders";
dataGrid.DataSource = this.nwindDataSet1.Customers;
}
else
{
dataGrid.DataMember = "";
dataGrid.DataSource = detailView.DataSource;
}
}
}
}