This is a migrated thread and some comments may be shown as answers.
Using a non-Telerik usercontrol in the gridview/wrapping a usercontrol in a RadElement wrapper? (C#)
1 Answer 86 Views
This is a migrated thread and some comments may be shown as answers.
Kenneth Jackson
Top achievements
Rank 1
Kenneth Jackson asked on 02 Jul 2009, 12:02 PM
Hi

I'm on a tight schedule and have put many hours of work into a usercontrol that does a bunch of stuff, automatic syntax highlighting based on list and db lookups, validation as you type and so on and so forth.

I did all of this on the assumption that, like the control set I worked with in my previous job, the Telerik Grid would provide some means of created a custom column that used my control.

However, having started work on the actual grid, I can find no way of doing this. After my initial efforts bore no fruit I searched extensively for ways of doing it both here and elsewhere on the Web and found nothing.

The code fragments I have found all require that one uses a class that is inherited from RadElement. Since the control I have, which represents many hours of work, is already written and I'm on a tight schedule, I _don't_ want to rewrite the whole thing from scratch based on a RadElement derived control. And C# doesn't allow multiple inheritance.

So the only thing I can think of is to somehow wrap my usercontrol in a class inherited from RadElement. My assumption is that it is possible to override certain painting and editing events inherited from the RadElement class so that they present my usercontrol. But the documentation of RadElement's members is kinda minimal - auto-documented code minimal. There's no explanation of what any of the events or functions are FOR, just descriptions of their signatures.

Is what I'm attempting possible? If so, how do I proceed?

Thanks in anticipation :)

1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 03 Jul 2009, 06:50 PM
Hello Kenneth Jackson,

Yes, this is possible. You can wrap your control inside a RadHostItem. Then create a custom cell element that will contain the RadHostItem.

I have prepared a code sample that uses the MS Label control. Please take a look at the sample:

void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e) 
    GridViewDataColumn column = e.Column as GridViewDataColumn; 
    if (e.Row is GridDataRowElement && column != null && column.FieldName == "Name"
    { 
        e.CellType = typeof(MyCell); 
    } 
 
public class MyCell : GridDataCellElement 
    RadLabel label; 
 
    public MyCell(GridViewColumn column, GridRowElement row) 
        : base(column, row) 
    { 
    } 
 
    protected override void CreateChildElements() 
    { 
        base.CreateChildElements(); 
        label = new RadLabel(); 
        this.Children.Add(new RadHostItem(label)); 
    } 
 
    protected override void SetContentCore(object value) 
    { 
        label.Text = value == null ? "" : value.ToString(); 
    }         

I hope this helps. If you need further assistance, I will be glad to help.

Kind regards,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Asked by
Kenneth Jackson
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or