Actually I can not understand why an incomprehensible phenomenon occurs, when the grid is initialized, the text in the cell appears and immediately disappears.

DataSet ds = core.getBid(); dg_bid.DataSource = ds.Tables[0]; dg_bid.AllowUserToAddRows = false; dg_bid.RowHeadersVisible = false; dg_bid.ReadOnly = false; DataGridViewTextBoxColumn navi; navi = new DataGridViewTextBoxColumn(); navi.Name = "Navigation"; navi.DataPropertyName = "Navigation"; navi.HeaderText = "Маршрут"; navi.ValueType = typeof(string); navi.ReadOnly = false; navi.Visible = true; navi.FillWeight = 250; dg_bid.Columns["id"].Visible = false; dg_bid.Columns["num"].HeaderText = "#"; dg_bid.Columns["create_date"].ValueType = typeof(DateTime); dg_bid.Columns["create_date"].HeaderText = "Дата"; dg_bid.Columns.Add(navi); for (int i = 0; i < dg_bid.Rows.Count; i++) { //Маршрут string bidID = dg_bid.Rows[i].Cells["id"].Value.ToString(); string nav_text = core.navi(bidID).ToString(); dg_bid.Rows[i].Cells["Navigation"].Value = nav_text; } 

The rest of the columns are loaded normally, incomprehensible only with the created column "Navigation", the grid has ReadOnly = false; What could be causing this?

    2 answers 2

     for (int i = 0; i < dg_bid.Rows.Count; i++) { //Маршрут string bidID = dg_bid.Rows[i].Cells["id"].Value.ToString(); string nav_text = core.navi(bidID).ToString(); ds.Tables[0].Rows[i].BeginEdit(); dataSet11.Tables[i].Rows[0]["Navigation"] = nav_text; ds.Tables[0].Rows[i].EndEdit(); } 
    • The column "Navigation" is created programmatically, it is not in the table. Therefore, you give the error: "The column" Navigation "does not belong to the Table table.". But thanks for pushing towards solving this issue. - Artneo

    After determining the DataSet ds = core.getBid(); Add a new column to ds, because it does not exist ds.Tables[0].Columns.Add("navigation"); . Next, we add a column programmatically in the DataGridView:

     DataGridViewTextBoxColumn navi = new DataGridViewTextBoxColumn(); navi.Name = "Navigation"; navi.DataPropertyName = "navigation"; navi.HeaderText = "Маршрут"; navi.ReadOnly = true; 

    navi.DataPropertyName = "navigation"; The name of the column must match the name of the previously created column in the Dataset in order for the data from the DataSet to be output to this column themselves.

    Now write the data to this column.

     for (int i = 0; i < dg_bid.Rows.Count; i++) { //Маршрут string bidID = dg_bid.Rows[i].Cells["id"].Value.ToString(); string nav_text = core.navi(bidID).ToString(); ds.Tables[0].Rows[i].BeginEdit(); ds.Tables[0].Rows[i]["navigation"] = nav_text; ds.Tables[0].Rows[i].EndEdit(); } 

    Now, when displaying in the grid, the text does not disappear in the column.