Winform has 2 grids. I display related tables from the SQL Server database to them.
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. Such as Id) Can the DataTable be used? If possible an example
After you set the DataSource for both grids, you can set the Visible property for the Id column to false.
Assuming the DefaultView is a GridView, the following code should do the job.
(gridControl1.DefaultView as GridView).Columns["Id"].Visible = false;