This is a migrated thread and some comments may be shown as answers.

Command Button put to center

4 Answers 13 Views
This is a migrated thread and some comments may be shown as answers.
Moe
Top achievements
Rank 1
Veteran
Moe asked on 30 Jul 2020, 07:35 AM

Hi Admin,

 

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

 

Thanks

Moe

4 Answers, 1 is accepted

Sort by
0
Nadya
Telerik team
answered on 30 Jul 2020, 03:39 PM

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

0
Moe
Top achievements
Rank 1
Veteran
answered on 31 Jul 2020, 01:15 PM

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

0
Nadya
Telerik team
answered on 31 Jul 2020, 02:01 PM

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

0
Moe
Top achievements
Rank 1
Veteran
answered on 03 Aug 2020, 03:35 AM

Hi Nadya,

 

Thanks for your reply and it is working for me .

Thank so much.

 

Thanks

Moe

Asked by
Moe
Top achievements
Rank 1
Veteran
Answers by
Nadya
Telerik team
Moe
Top achievements
Rank 1
Veteran
Share this question
or