I am trying to change the type of a column from a numeric to a lowercase one, but it does not work. What could be the problem ?

The data is pulled from the database Mysql, the field type is "type" smallint (1)

kontr_dg - DataGridView

kontr_dg.Columns["type"].ValueType = typeof(string); string _typeID = kontr_dg.Rows[i].Cells["type"].Value.ToString(); string _type = core.kontr_type(_typeID); kontr_dg.Rows[i].Cells["type"].Value = _type.ToString(); //Перевод числа в строку public string kontr_type(string type) { string _type; if (type == "1") _type = "Заказчик"; else _type = "Перевозчик"; return _type; } 

error output Column type does not change in DataGridView

  • How do you create your kontr_dg? Whence the need for kontr_dg.Columns ["type"]. ValueType = typeof (string); ? Remove all unnecessary and see in the debugger how kontr_dg.Rows [i] .Cells ["type"] is processed. Value = "Test"; - Alexander Muksimov

1 answer 1

datagrid is filled from DB. The need was needed so that instead of the value 1, there was the value "Customer". The problem was solved by changing the field type in the database from smallint to varchar.