Listbox cell multiline

i have set my column to editable with:


i can click on the cell and edit text… but on leavin cell it displays only 1 line of text.
Can i somehow set it to display more than 1 line?

Also i want to be able to create a new line with “enter” key on keyboard when editing.
Now when i click “enter” it’s leaving the cell…

Any suggestions?

Draw the text in the cell yourself in the PaintCellText (or if API 1 CellTextPaint) event.

1 Like

For a multi-line cell in a listbox I use the PaintCellText event.

Function PaintCellText(g as Graphics, row as Integer, column as Integer, x as Integer, y as Integer) as Boolean
  Var w, h As Integer
  w = g.Width
  h = g.Height
  // if the rowheight or columnwidth are too small this prevents the drawing (and errors in any calculations)
  If w < 1 Or h < 1 Then Return False 
  // Store the string value of the cell
  Var t As String = Me.CellTextAt(row, column) 
  // Set styles, if needed
  g.Bold = False
  g.Italic = False
  g.Underline = False
  g.FontSize = 12
  // Get the size of the text
  Var tw, th As Integer
  tw = g.TextWidth(t) ' The width
  th = g.TextHeight(t, tw + 1) ' The height
  // Variables for the position of the text
  Var xx, yy As Integer ' the yy variable controls the vertical offset, if needed.
  // Calculate the horizontal position
  Select Case Me.ColumnAlignmentAt(column)
  Case DesktopListBox.Alignments.Center
    xx = (w - tw) / 2
  Case DesktopListBox.Alignments.Right, DesktopListBox.Alignments.Decimal
    xx = w - tw
  Case Else ' Left alignment
    xx = 0
  // Draw the text
  g.DrawText t, xx, yy + g.FontAscent
  // Increase the YY value, if you need to draw more text
  yy = yy + th
  // You can add more text by copying the code above
  // You could draw each line individually, and make the top-line bold if you want.
  // sky is the limit... 

  Return True
End Function

You might want to catch the keyboard event and return True whenever the “enter” key is pressed.
Of course, you need to add the EndOfLine at the cursor-location in this event as well.