0

I am using a varchar(max) in a column of datatable. I am then populating my datagridview with the query.

Everything is going fine getting the data to the dgv. The problem is my crlf are not displaying correctly in the datagridview.

It is displaying all as one line of text.

For example:

Starting GetWebsiteSettings.
Starting GetTokenShowHideSettings.
End GetTokenShowHideSettings.
End GetWebsiteSettings.

Is displaying as

Starting GetWebsiteSettings.Starting GetTokenShowHideSettings.End GetTokenShowHideSettings.End GetWebsiteSettings.

This is how I am populating the dgv:

private void button_Search_Click(object sender, EventArgs e)
{
  using (var model = new SuburbanPortalEntities())
  {
    var qry = from logs in model.Logs
              select logs;

    Guid corpid;
    if (Guid.TryParse(textBox_CorporationGuid.Text, out corpid))
    {
      qry = qry.Where(x => x.CorporationId == corpid);
    }

    Guid tokenid;
    if (Guid.TryParse(textBox_TokenId.Text, out tokenid))
    {
      qry = qry.Where(x => x.TokenId == tokenid);
    }

    if (checkBox_DisplayErrors.Checked)
    {
      qry = qry.Where(x => x.IsException);
    }

    if (checkBox_DisplayWarnings.Checked)
    {
      qry = qry.Where(x => x.IsWarning);
    }

    qry = qry.OrderBy(x => x.LogDateTime);

    dataGridView1.DataSource = qry;

    dataGridView1.Columns["LogId"].Visible = false;
    dataGridView1.Columns["ClientHeaders"].Visible = false;
    dataGridView1.Columns["SourceId"].Visible = false;

  }
}

How do I get the datagridview to display the text correctly?

King King
  • 61,710
  • 16
  • 105
  • 130
ErocM
  • 4,505
  • 24
  • 94
  • 161
  • Metro? WinForms? WPF? Silverlight? Windows Phone? ASP.Net? MonoTouch? – SLaks Aug 09 '13 at 15:52
  • It looks like that the `DataGridView` can't display multi-line text. You should look for another kind of control. – King King Aug 09 '13 at 16:06
  • @ErocM as I said, you should find another kind of `DataGridView`, as far as I know the standard `DataGridView` can't display multiline. You also may want to search for `multiline datagridview` – King King Aug 09 '13 at 16:12
  • @ErocM here http://stackoverflow.com/questions/1706454/c-multiline-text-in-datagridview-control it can help you. – King King Aug 09 '13 at 16:14

1 Answers1

1

I found this post

dataGridView1.Columns["Message"].DefaultCellStyle.WrapMode = 
                                                      DataGridViewTriState.True;
Community
  • 1
  • 1
ErocM
  • 4,505
  • 24
  • 94
  • 161
  • 1
    As someone suggested, you should also add this `dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders;` so that the row height can be enough to show all the text. – King King Aug 09 '13 at 16:17