Hi,
I was trying to write a custom column having textbox and an image to be useds as lookup column. I tried following code and it work perfectly except the image did not appear in center. Please advise.
Thanks,
devoas
I was trying to write a custom column having textbox and an image to be useds as lookup column. I tried following code and it work perfectly except the image did not appear in center. Please advise.
void radGridView1_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
if (e.Column.Name == "Lookup")
{
RadImageItem imgElement;
imgElement = new RadImageItem();
imgElement.Margin = new Padding(0, 2, 0, 0);
imgElement.Alignment = ContentAlignment.MiddleCenter;
imgElement.Image = Properties.Resources.hd_find.ToBitmap();
//imgElement.MinSize = new Size(20, 5);
imgElement.Size = new Size(50, 5);
imgElement.AutoSize = false;
//imgElement.AutoSizeMode = RadAutoSizeMode.FitToAvailableSize;
this.radGridView1.CurrentCell.Children.Add(imgElement);
if (!tbSubscribed)
{
RadTextBoxEditor tbEditor = this.radGridView1.ActiveEditor as RadTextBoxEditor;
if (tbEditor != null)
{
tbSubscribed = true;
RadTextBoxEditorElement tbElement = (RadTextBoxEditorElement)tbEditor.EditorElement;
tbElement.KeyDown += new KeyEventHandler(tbElement_KeyDown);
}
}
}
}
void radGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
{
if (e.Column.Name == "Lookup")
{
if (this.radGridView1.CurrentCell.Children.Count == 1)
{
this.radGridView1.CurrentCell.Children.RemoveAt(0);
}
}
}
void tbElement_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F1)
{
((RadTextBoxEditorElement)sender).Text = "Default text";
}
}
void radGridView1_CreateCell(object sender, Telerik.WinControls.UI.GridViewCreateCellEventArgs e)
{
if (e.Row is GridDataRowElement)
{
if (e.Column.Name == "Lookup")
{
e.CellType = typeof(RadTextBoxExtCellElement);
}
}
}
public class RadTextBoxExtCellElement : GridDataCellElement
{
private int imageWidth = 30;
private int imagePadding = 2;
public RadTextBoxExtCellElement(GridViewColumn column, GridRowElement row)
: base(column, row)
{
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(GridDataCellElement);
}
}
protected override SizeF ArrangeOverride(SizeF finalSize)
{
base.ArrangeOverride(finalSize);
if (this.Children.Count == 2)
{
RectangleF rect = GetClientRectangle(finalSize);
RectangleF rectEdit = new RectangleF(rect.X, rect.Y, rect.Width - (imageWidth + imagePadding), rect.Height);
RectangleF rectImage = new RectangleF(rectEdit.Right + imagePadding, rect.Y, imageWidth, rect.Y);
this.Children[0].Arrange(rectEdit);
this.Children[1].Arrange(rectImage);
}
return finalSize;
}
Thanks,
devoas