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

2 GridControl and linked tables in SQL Server

Winform 有 2 个网格。我向他们显示 SQL 服务器数据库中的相关表格。

代码如下:

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;

请帮我弄清楚如何在 GridControl 中隐藏不需要的列。比如Id)DataTable可以用吗?如果可能的话,一个例子

为两个网格设置 DataSource 后,您可以将 Id 列的 Visible 属性 设置为 false。

假设 DefaultView 是一个 GridView,下面的代码应该可以完成这项工作。

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