简体   繁体   English

2 SQL 服务器中的 GridControl 和链接表

[英]2 GridControl and linked tables in SQL Server

Winform has 2 grids. Winform 有 2 个网格。 I display related tables from the SQL Server database to them.我将 SQL 服务器数据库中的相关表显示给他们。

Here is the code:这是代码:

string connectionString = ConfigurationManager.ConnectionStrings["connectionSIPiT"].ConnectionString;

string command = "SELECT UserID, UserName,Login, idArm FROM Users";
string command2 = "SELECT id, name FROM arm";

sqlConnection = new SqlConnection(connectionString);

SqlDataAdapter adapter = new SqlDataAdapter(command2, sqlConnection);
SqlDataAdapter adapter1 = new SqlDataAdapter(command, sqlConnection);

DataSet dataset1 = new DataSet();
adapter.Fill(dataset1, "arm");
adapter1.Fill(dataset1, "Users");

DataColumn keyColumn = dataset1.Tables[0].Columns[0];
DataColumn foreignKeyColumn = dataset1.Tables[1].Columns[3];
dataset1.Relations.Add("armUsers", keyColumn, foreignKeyColumn);

bindingSource1.DataSource = dataset1;
bindingSource1.DataMember = "arm";

bindingSource2.DataSource = bindingSource1;
bindingSource2.DataMember = "armUsers";

gridControl1.DataSource = bindingSource1;
gridControl2.DataSource = bindingSource2;

Please help me figure out how to hide unnecessary columns in the GridControl.请帮我弄清楚如何在 GridControl 中隐藏不必要的列。 Such as Id) Can the DataTable be used?如Id)DataTable可以用吗? If possible an example如果可能的话,举个例子

After you set the DataSource for both grids, you can set the Visible property for the Id column to false.为两个网格设置 DataSource 后,可以将 Id 列的 Visible 属性设置为 false。

Assuming the DefaultView is a GridView, the following code should do the job.假设 DefaultView 是 GridView,下面的代码应该可以完成这项工作。

(gridControl1.DefaultView as GridView).Columns["Id"].Visible = false;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM