C1Flexgid Editor text alignment - left center?

Posted by: hdle on 21 September 2023, 1:13 pm EST

  • Posted 21 September 2023, 1:13 pm EST

    I am trying to set the text alignment for the value editor in a cell to left center, but no luck. I have a case where the value column can be very wide. The display value is set to left center, next to the column containing the value header. The problem is that when user start editing, the value is way to the right.

    Setting Col TextAlign only applies to display value.

    Setting EditorStyle TextAlign does nothing.

    How can I achieve this? in version 4.0.20193.393

    Thanks,

    Hai

  • Posted 21 September 2023, 11:48 pm EST

    Hello Hai,

    The text alignment of the columns with the string datatype is default left and the same alignment is there when editing. For the number columns where the alignment is to the right, you can set the TextAlign property of those columns to the left and for editing you can set a TextBox as an editor and set its TextAlign property accordingly.

     TextBox tb = new TextBox();
     tb.TextAlign = HorizontalAlignment.Left;
     c1FlexGrid1.Cols[3].Editor = tb;

    I hope it helps. If you need any further information, please let us know.

    Regards,

    Prabhat Sharma.

  • Posted 22 September 2023, 12:20 am EST

    Prabhat,

    Thank you for the quick reply. Your suggestion worked, but it doesn’t have the same them style. Why does EditorStyle.TextAlign not applied to the built in editor?

    Thanks,

    Hai

  • Posted 22 September 2023, 3:56 am EST

    Hi Hai,

    I think it should also work if you handle the “SetupEditor” event of C1FlexGrid and do this:

    private void c1FlexGrid_SetupEditor(object sender, C1.Win.FlexGrid.RowColEventArgs e)
    {
      if (e.Col == relevantCol)
      {
        TextBox textBoxEditor = (TextBox)this.hgTable.Editor;
        textBoxEditor.TextAlign = HorizontalAlignment.Left;
      }
    }

    This avoids creating a new TextBox. If you have other editable columns that shall not be left aligned, you have to reset the TextAlign for them.

    Best regards

    Wolfgang

  • Posted 25 September 2023, 12:20 am EST

    Hello Hai,

    We too can observe the same behavior at our with the Editor Style’s TextAlign property and report to the development team. We will let you know as soon as we get the update from the developers.

    [Internal Tracking ID: C1WIN-31120]

    For the time being, we request you to use the given workaround for now.

    @Wolfgang, thanks for the workaround.

    Regards,

    Prabhat Sharma.

  • Posted 25 September 2023, 9:53 am EST

    @Wolfgang,

    Your approach is much better because it also retains the EditorStyle and auto select on focus. I did the new text box approach, but it requires setting the style of the text box and force select content on click (other event doesn’t work).

    Thanks everyone for looking at this and helping.

    Hai

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels