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
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
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
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
Hi Nadya,
Thanks for your reply and it is working for me .
Thank so much.
Thanks
Moe