Column chooser Content Alignment

2 posts, 0 answers
  1. Matt
    Matt avatar
    3 posts
    Member since:
    Nov 2015

    Posted 16 Dec 2015 Link to this post

    I am trying to left align the text in the column chooser. When I walk through it debugging, I can see the value successfully get updated but the content is still middle aligned when shown. What is the correct way to left align the text in column chooser?

    This is what I am currently doing, the positioning portion works correctly but not the content alignment.

    private void ConfigureOrderGrid()
    {
            orders_radGridView.ColumnChooser.Shown += (o, args) =>   orders_radGridView.ColumnChooser.SetPosition();
    }
     
    public static void SetPosition(this GridViewColumnChooser chooser)
    {           
        var gridPoint = chooser.GridRootElement.PointToScreen(new Point(0));
        var x = gridPoint.X + chooser.GridRootElement.Size.Width;
        chooser.DesktopLocation = new Point(x, gridPoint.Y);
        chooser.StartPosition = FormStartPosition.Manual;
        chooser.ColumnChooserControl.ColumnChooserElement.TextAlignment =   ContentAlignment.MiddleLeft;
    }

     

  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 17 Dec 2015 Link to this post

    Hi Matt,

    Thank you for writing.

    The column chooser is being dynamically created when opened, hence your settings are getting applied just the first time - because radGridView1.ColumnChooser will give you just the initial instance, and you are not subscribed to the Shown event of following instances.

    For the purpose we have a ColumnChooserCreated event, which gets fired when a new instance of the chooser is being created. In it, you can subscribe to the Shown event and use your handler:
    void ColumnChooser_Shown(object sender, EventArgs e)
    {
        var gridPoint = radGridView1.ColumnChooser.GridRootElement.PointToScreen(new System.Drawing.Point(0));
        var x = gridPoint.X + radGridView1.ColumnChooser.GridRootElement.Size.Width;
        radGridView1.ColumnChooser.DesktopLocation = new System.Drawing.Point(x, gridPoint.Y);
        radGridView1.ColumnChooser.StartPosition = FormStartPosition.Manual;
        radGridView1.ColumnChooser.ColumnChooserControl.ColumnChooserElement.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
    }
     
    void radGridView1_ColumnChooserCreated(object sender, ColumnChooserCreatedEventArgs e)
    {
        e.ColumnChooser.Shown+=ColumnChooser_Shown;
    }

    I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

    Regards,
    Stefan
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top