devexpress 中的树视图 Datagridview
Tree View Datagridview in devexpress
我多次尝试创建 table 的主视图及其详细信息,并在 Gridcontrol 中可视化(来自 Devexpress)
这是代码
*我不想依赖Devexpress设计师自动生成代码!
' DEFINE A DATASET TO HOLD TABLES INSIDE
Dim dataset As New DataSet
'IF THE CONNECTION IS POSSIBLE THEN PROCCEED
If sqlcontrol.HasConnection Then
' SELECT ALL RECORDS FROM THE SUPPLIERS TABLE (MASTER TABLE)
sqlcontrol.ExecQuery("SELECT * FROM [Suppliers]")
' FILL IN THAT TABLE INTO THE DATASET
dataset.Tables.Add(sqlcontrol.SQLdatatable)
' SELECT ALL RECORDS FROM THE SUPPLIERSPERSONNEL (DETAIL TABLE)
sqlcontrol.ExecQuery("SELECT * FROM [SuppliersPersonnel]")
'FILL IN THAT TABLE INTO THE DATASET
dataset.Tables.Add(sqlcontrol.SQLdatatable)
'INVOKE THE BINDING SOURCE INTO THE GRIDVIEW
Me.GridControl1.DataSource = dataset
End If
希望它能工作,但不像主从视图。
它单独显示了每个 table。
数据集本身确实包含表,但是表之间的关系丢失并且没有从 SQL 表中检索,因此为什么需要在 VB 中的数据集中添加这种关系.
所以代码如下:
' DEFINE A DATASET TO HOLD TABLES INSIDE
Dim dataset As New DataSet
'IF THE CONNECTION IS POSSIBLE THEN PROCCEED
If sqlcontrol.HasConnection Then
' SELECT ALL RECORDS FROM THE SUPPLIERS TABLE (MASTER TABLE)
sqlcontrol.ExecQuery("SELECT * FROM [Suppliers]")
' FILL IN THAT TABLE INTO THE DATASET
dataset.Tables.Add(sqlcontrol.SQLdatatable)
' SELECT ALL RECORDS FROM THE SUPPLIERSPERSONNEL (DETAIL TABLE)
sqlcontrol.ExecQuery("SELECT * FROM [SuppliersPersonnel]")
'FILL IN THAT TABLE INTO THE DATASET
dataset.Tables.Add(sqlcontrol.SQLdatatable)
'Add the relation to the dataset
dataset.relations.add("CustomRelation",
dataset.tables(0).columns(0),
dataset.tables(1).columns(1), false)
'INVOKE THE BINDING SOURCE INTO THE GRIDVIEW
Me.GridControl1.DataSource = dataset
End If
通过这种方式,Gridcontrol 将按预期工作!
我多次尝试创建 table 的主视图及其详细信息,并在 Gridcontrol 中可视化(来自 Devexpress) 这是代码 *我不想依赖Devexpress设计师自动生成代码!
' DEFINE A DATASET TO HOLD TABLES INSIDE
Dim dataset As New DataSet
'IF THE CONNECTION IS POSSIBLE THEN PROCCEED
If sqlcontrol.HasConnection Then
' SELECT ALL RECORDS FROM THE SUPPLIERS TABLE (MASTER TABLE)
sqlcontrol.ExecQuery("SELECT * FROM [Suppliers]")
' FILL IN THAT TABLE INTO THE DATASET
dataset.Tables.Add(sqlcontrol.SQLdatatable)
' SELECT ALL RECORDS FROM THE SUPPLIERSPERSONNEL (DETAIL TABLE)
sqlcontrol.ExecQuery("SELECT * FROM [SuppliersPersonnel]")
'FILL IN THAT TABLE INTO THE DATASET
dataset.Tables.Add(sqlcontrol.SQLdatatable)
'INVOKE THE BINDING SOURCE INTO THE GRIDVIEW
Me.GridControl1.DataSource = dataset
End If
希望它能工作,但不像主从视图。 它单独显示了每个 table。
数据集本身确实包含表,但是表之间的关系丢失并且没有从 SQL 表中检索,因此为什么需要在 VB 中的数据集中添加这种关系. 所以代码如下:
' DEFINE A DATASET TO HOLD TABLES INSIDE
Dim dataset As New DataSet
'IF THE CONNECTION IS POSSIBLE THEN PROCCEED
If sqlcontrol.HasConnection Then
' SELECT ALL RECORDS FROM THE SUPPLIERS TABLE (MASTER TABLE)
sqlcontrol.ExecQuery("SELECT * FROM [Suppliers]")
' FILL IN THAT TABLE INTO THE DATASET
dataset.Tables.Add(sqlcontrol.SQLdatatable)
' SELECT ALL RECORDS FROM THE SUPPLIERSPERSONNEL (DETAIL TABLE)
sqlcontrol.ExecQuery("SELECT * FROM [SuppliersPersonnel]")
'FILL IN THAT TABLE INTO THE DATASET
dataset.Tables.Add(sqlcontrol.SQLdatatable)
'Add the relation to the dataset
dataset.relations.add("CustomRelation",
dataset.tables(0).columns(0),
dataset.tables(1).columns(1), false)
'INVOKE THE BINDING SOURCE INTO THE GRIDVIEW
Me.GridControl1.DataSource = dataset
End If
通过这种方式,Gridcontrol 将按预期工作!