我多次尝试创建表的主视图及其详细信息,并在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
希望它有效,但不像主 - 细节视图。 它自己展示了每张桌子。
答案 0 :(得分:0)
数据集本身确实包含表,但是表之间的关系缺失并且没有从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按预期工作!