Command Button put to center

5 posts, 0 answers
  1. Moe
    Moe avatar
    30 posts
    Member since:
    Jan 2018

    Posted 30 Jul Link to this post

    Hi Admin,

     

    I would like to do command button put to center by vertical ( black square location). please see photo.

     

    Thanks

    Moe

  2. Nadya
    Admin
    Nadya avatar
    341 posts

    Posted 30 Jul Link to this post

    Hello, Moe,

    In order to align the image in GridViewCommandColumn, you should handle the CellFormatting event. More information is available here: https://docs.telerik.com/devtools/winforms/controls/gridview/cells/formating-examples/command-cell

    Please refer to the following code snippet:

    private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        if (e.CellElement.ColumnInfo is GridViewCommandColumn)
        {
            // This is how we get the RadButtonElement instance from the cell
            RadButtonElement button = (RadButtonElement)e.CellElement.Children[0];
            button.Image = Resources.SearchFolder;
            button.ImageAlignment = ContentAlignment.MiddleCenter;
        }
        else
        {
            e.CellElement.ResetValue(LightVisualElement.ImageProperty, ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.ImageAlignmentProperty, ValueResetFlags.Local);
        }
    }
    

    I hope this helps. Should you have other questions do not hesitate to ask.

    Regards,
    Nadya
    Progress Telerik

  3. Moe
    Moe avatar
    30 posts
    Member since:
    Jan 2018

    Posted 31 Jul in reply to Nadya Link to this post

    Hi Nadya,

    I don’t button size too big. my button size show in picture. I want that button put to center show in picture( each row of middle loction). Now my button location in top. 

     

    Thanks,

    Moe

  4. Nadya
    Admin
    Nadya avatar
    341 posts

    Posted 31 Jul Link to this post

    Hello, Moe,

    Please excuse me that I did not notice that the buttons have a smaller size in your picture. In order to put the button itself into the middle center of the cell, you should set RadButtonElement.Alignment property to MiddleCenter:

    private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        if (e.CellElement.ColumnInfo is GridViewCommandColumn)
        {
            // This is how we get the RadButtonElement instance from the cell
            RadButtonElement button = (RadButtonElement)e.CellElement.Children[0];
            button.MaxSize = new Size(50, 20);
            //set button Alignment
            button.Alignment = ContentAlignment.MiddleCenter;
            button.Image = Resources.SearchFolder;
            button.ImageAlignment = ContentAlignment.MiddleCenter;
        }
        else
        {
            e.CellElement.ResetValue(LightVisualElement.ImageProperty, ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.ImageAlignmentProperty, ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.AlignmentProperty, ValueResetFlags.Local);
        }
    }
    

    Do not hesitate to contact me if you have further questions.

    Regards,
    Nadya
    Progress Telerik

  5. Moe
    Moe avatar
    30 posts
    Member since:
    Jan 2018

    Posted 02 Aug in reply to Nadya Link to this post

    Hi Nadya,

     

    Thanks for your reply and it is working for me .

    Thank so much.

     

    Thanks

    Moe

Back to Top