I have a command column in a gridview. I am trying to style the button using either the RowFormatting event or the CellFormatting event. I found some code in one of the posts on how to modify the children and have adapted it to try to get the button styled properly.
I originally used the CellFormatting event, then I tried the RowFormatting event but both shared the same problem. For some reason, the size of the button is not properly set when the grid renders. If I click the button, expand another row, or do something to invalidate the button layout, it jumps to the correct size. I have tried all kinds of things to fix this and explicitly set the button size.
I posted an image that depicts my problem as well:
http://www.thinkconvergence.com/telerik_issue.jpg
Here is a sample of my code from the CellFormatting event:
RadButtonElement button = e.CellElement.Children[0] as RadButtonElement;
if (button != null)
{
button.ForeColor = Color.White;
BorderPrimitive border = ((BorderPrimitive)button.GetChildrenByType(typeof(BorderPrimitive))[0]);
border.ForeColor = Color.FromArgb(0, 87, 42);
border.InnerColor = Color.FromArgb(0, 56, 27);
border.GradientStyle = GradientStyles.Solid;
FillPrimitive fill = ((FillPrimitive)button.GetChildrenByType(typeof(FillPrimitive))[0]);
fill.GradientStyle = GradientStyles.Glass;
fill.BackColor = Color.FromArgb(71, 133, 101);
fill.BackColor2 = Color.FromArgb(71, 133, 101);
fill.BackColor3 = Color.FromArgb(0, 92, 44);
fill.BackColor4 = Color.FromArgb(0, 106, 51);
button.AutoSize = false;
button.Size = new Size(64, 24); //THIS IS WHAT DOESNT SEEM TO WORK CORRECTLY
button.Margin = new Padding(5);
}
I originally used the CellFormatting event, then I tried the RowFormatting event but both shared the same problem. For some reason, the size of the button is not properly set when the grid renders. If I click the button, expand another row, or do something to invalidate the button layout, it jumps to the correct size. I have tried all kinds of things to fix this and explicitly set the button size.
I posted an image that depicts my problem as well:
http://www.thinkconvergence.com/telerik_issue.jpg
Here is a sample of my code from the CellFormatting event:
RadButtonElement button = e.CellElement.Children[0] as RadButtonElement;
if (button != null)
{
button.ForeColor = Color.White;
BorderPrimitive border = ((BorderPrimitive)button.GetChildrenByType(typeof(BorderPrimitive))[0]);
border.ForeColor = Color.FromArgb(0, 87, 42);
border.InnerColor = Color.FromArgb(0, 56, 27);
border.GradientStyle = GradientStyles.Solid;
FillPrimitive fill = ((FillPrimitive)button.GetChildrenByType(typeof(FillPrimitive))[0]);
fill.GradientStyle = GradientStyles.Glass;
fill.BackColor = Color.FromArgb(71, 133, 101);
fill.BackColor2 = Color.FromArgb(71, 133, 101);
fill.BackColor3 = Color.FromArgb(0, 92, 44);
fill.BackColor4 = Color.FromArgb(0, 106, 51);
button.AutoSize = false;
button.Size = new Size(64, 24); //THIS IS WHAT DOESNT SEEM TO WORK CORRECTLY
button.Margin = new Padding(5);
}