1

I have a datagridview with a textboxcolumn. If I want to display a text that contains a vbTab then this Tab is simply removed and no tabulation is displayed.

If I write for example "text" & vbTab & "text" programmatically into a datagridview's cell the displayed text is texttext. Works fine in a normal textbox tough.

Can this somehow be corrected? Thanks

sharkyenergy
  • 3,842
  • 10
  • 46
  • 97

1 Answers1

0

You may use the DataGridViewCellFormatting event to modify the appearance of the text. In the following code, I replaced tabs by a vertical bar (but you can change that).

Private Sub dataGridView1_CellFormatting(ByVal sender As Object, _
      ByVal e As DataGridViewCellFormattingEventArgs) _
      Handles dataGridView1.CellFormatting
  If Me.dataGridView1.Columns(e.ColumnIndex).Name = "TheTextColumnName"  Then
    If e.Value IsNot Nothing Then 
        e.Value = CType(e.Value, String).Replace(vbtab,"|")
    End If
  End If
End Sub
Graffito
  • 1,658
  • 1
  • 11
  • 10
  • thanks, i already did this but it does not solve the problem. the advantage of the tabulator is that it aligns the words.. – sharkyenergy Jul 10 '15 at 13:35
  • If handling the CellPainting event, you will use use Graphics.DrawString() to display the cell text. You can then Split() the string using tab separator and make as many Graphics.DrawString as tabbed items in your string in order to take into account alignments. – Graffito Jul 10 '15 at 13:55