I am trying to fill my DGV from DB, but one of the columns contains a row that is too long and therefore the cells are empty. I would just like to truncate the string, but the methods that are lower in the code do not work. How to be? On the screen the problem itself.

string nameConn = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; string search = "SELECT * myTableName"; using (SqlConnection con = new SqlConnection(nameConn)) { using (SqlCommand comm = new SqlCommand(search, con)) { comm.CommandType = CommandType.Text; using (SqlDataAdapter sda = new SqlDataAdapter(comm)) { using (DataTable data = new DataTable()) { try { sda.Fill(data); } catch (Exception exc) { MessageBox.Show(exc.Message); } dataGridView5.DataSource = data; //CType(dataGridView5.Columns(4), DataGridViewTextBoxColumn).MaxInputLength = 5; //dataGridView5.Columns[4].MaxInputLength = 5; 

enter image description here

  • 2
    String.Substring , not? - AK
  • @AK yes, it came out :) thanks - Nataila
  • Then write the answer - suddenly someone else will come in handy. - AK
  • I did not understand. The long line is trimmed by the grid itself, at the end appears ellipsis (ellipsis). Not? Or do spaces appear at the beginning of the line and should they be cut off? Then, the most correct would be to trim these spaces before inserting into the database ( Trim method). - Alexander Petrov
  • As far as I understand @AlexanderPetrov, this is just a very long string, so the DGV leaves just an empty cell. Because when I write all this into a json type document, I have about 3000 lines - Nataila am

0