Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well I think I have it. In case anyone is interested here is the code below:</p> <pre><code>public class MyTextBoxCell : DataGridViewTextBoxCell{ .... private static readonly int INDENTCOEFFICIENT = 5; protected override Size GetPreferredSize(Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize) { int indent = ((MyRow)OwningRow).Indent * INDENTCOEFFICIENT; Size s = base.GetPreferredSize(graphics, cellStyle, rowIndex, constraintSize); int textWidth = 2; //arbitrary amount if (Value != null) { string text = Value as string; textWidth = TextRenderer.MeasureText(text, cellStyle.Font).Width; } s.Width += textWidth + indent; return s; } private static readonly StringFormat strFmt = new StringFormat(StringFormatFlags.NoWrap); protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { DataGridViewPaintParts pp = DataGridViewPaintParts.Background | DataGridViewPaintParts.Border | DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.ErrorIcon; base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, pp); string text = formattedValue as string; int indent = ((MyRow)OwningRow).Indent * INDENTCOEFFICIENT; strFmt.Trimming = StringTrimming.EllipsisCharacter; Rectangle r = cellBounds; r.Offset(indent, 0); r.Inflate(-indent, 0); graphics.DrawString(text, cellStyle.Font, Brushes.Black, r, strFmt); } } </code></pre> <p>If anyone has a better way I would love to see your solution.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload