Answer the question
In order to leave comments, you need to log in
How to populate datagrid from datatable?
there is a datagrid where 2 columns of the required size are created and there is a datatable where I add row. when I write datagridview.datasource= dt; new columns appear on the right and are not added to those that exist, how to fix it?
the code
DataColumn name = new DataColumn("Названия", typeof(string));
DataColumn data = new DataColumn("Значения", typeof(string));
dt.Columns.AddRange(new DataColumn[] { name, data });
DataRow row1 = dt.NewRow();
row1[0] = "прибор";
row1[1] = "212211";
dt.Rows.Add(row1);
Answer the question
In order to leave comments, you need to log in
Delete your columns
In the code, then set up the display, like:
dataGridView1.Columns[0].HeaderText = "№";
dataGridView1.Columns[0].MinimumWidth = 25;
dataGridView1.Columns[0].Width = 40;
dataGridView1.Columns[0].Visible = true;
dataGridView1.Columns[1].HeaderText = "Спрятанная колонка";
dataGridView1.Columns[1].Visible = false;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question