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

Gridview template tutorial

1 Answer 215 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Anders
Top achievements
Rank 1
Anders asked on 04 Sep 2012, 12:45 PM
Hello

I have a class that holds two other classes Like this
public Class A
{
   Some properties From A
   some methods From A
}
 
public Class B
{
    some properties from B
    Some methods from A
}
 
public Class C
{
   public  Aclass a;
   public  Bclass b;
}
However I need to list a collection of Class c in a list where some columns shouldn't show, some should be readable only, some should have another Columnheader name than class property name. I figure I need to make a template class where I extend a gridview template class, however I am unable to find a tutorial on how to make such a template class

Any Information on this is appreciated.

----
Expected result
I am not exactly looking to change backgroundcolor or play music, but these are some of the things that are possible with a template
public Class Gridview
{
private void someMethod()
{
   gridview.Template=new Templ;
}
private
class templ : Template
{
put this information from these classes into those columns
make some columns do this
make each four row have a button that play a song
make the background appear as something specific depending on teh information it has
}
}

1 Answer, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 06 Sep 2012, 11:27 AM
Hi Anders,

Thank you for writing.

You can override the default RadGridViewElement and MasterGridViewTemplate to add your custom properties and behavior. Here is a example:
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Telerik.WinControls.UI.Data;
 
namespace Lab.Grid
{
    public partial class GridOverrideViewAndTemplateForm : Form
    {
        class MyMasterTemplate : MasterGridViewTemplate
        {
            public MyMasterTemplate()
            {
                this.DataSource = new ValueList<double>(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
            }
        }
 
        class MyGridViewElement : RadGridViewElement
        {
            protected override MasterGridViewTemplate CreateTemplate()
            {
                return new MyMasterTemplate();
            }
        }
 
        class MyGrid : RadGridView
        {
            protected override RadGridViewElement CreateGridViewElement()
            {
                return new MyGridViewElement();
            }
        }
 
        public GridOverrideViewAndTemplateForm()
        {
            InitializeComponent();
 
            MyGrid grid = new MyGrid();
            grid.Dock = DockStyle.Fill;
            grid.Parent = this;
        }
    }
}

I hope this helps.

All the best,
Julian Benkov
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Anders
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Share this question
or