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

Custom Column Documentation

12 Answers 233 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 10 Dec 2008, 03:10 AM
Hi,

I was wondering if there is an article or section that contains documentation to create your own GridViewDataColumns as well as IInputEditors.  I've tried searching the forums and the library's documentation but certain classes/interfaces don't even have a complete reference texts.



12 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 10 Dec 2008, 05:05 PM
Hi Mark,

Thank you for your question. Currently no, but we will add such - thanks for pointing out this omission on our side.

To help you with this task, I have created a sample project - please take a look at the attachment.

Do not hesitate to write me back if you have more questions.

Regards,
Nick
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
[Nean]
Top achievements
Rank 1
answered on 30 Jul 2009, 09:14 AM
Hi Nick,

That's very interesting. I have a similar problem. I want to create a custom Command Column. I want to have a DropDownMenu in my CommandCell to offer multiple options to the custommer in only one column. How can I do that sort of thing ?

And the other probnlem is in my CommandCellClick event How can I know, which item was clicked in the droopdown menu.

Thanks in advance,

[Nean]
0
Nick
Telerik team
answered on 30 Jul 2009, 10:52 AM
Hello [Nean],

Thank you for contacting us. Please check first whether you can use a combobox column. You can track down value changes. Then review the help topics about grid editors and especially custom editors.

Kind regards,
Nick
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.
0
[Nean]
Top achievements
Rank 1
answered on 30 Jul 2009, 11:02 AM
Thanks for your quick awnser.

I can probably use a RadComboBox, but it doesn't look like a professional menu. That's why I was wondering if it is possible to make a custom command column with a dropdownmenu (with icons). If there is not any possibility, i will look forward to the combobox, but it is not exactly what i'm looking for visually.

Regards,

[Nean]
0
Jack
Telerik team
answered on 30 Jul 2009, 11:32 AM
Hi [Nean],

You can use the custom cell element and add RadDropDownButtonElement inside. You should handle the Click event for the desired RadMenuItem. Here is a sample:

this.radGridView1.Columns.Add(new GridViewDataColumn("A""")); 
this.radGridView1.Columns["A"].Width = 100; 
 
void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e) 
    GridViewDataColumn column = e.Column as GridViewDataColumn; 
    if (column != null && column.UniqueName == "A" && e.Row is GridDataRowElement) 
    { 
        e.CellType = typeof(DropDownCellElement); 
    } 
 
public class DropDownCellElement : GridDataCellElement 
    RadDropDownButtonElement dropDown; 
 
    public DropDownCellElement(GridViewColumn column, GridRowElement row) 
        : base(column, row) 
    { 
    } 
 
    protected override void CreateChildElements() 
    { 
        base.CreateChildElements(); 
        dropDown = new RadDropDownButtonElement(); 
        dropDown.Text = "DropDown"
        dropDown.Items.Add(new RadMenuItem("Item 1")); 
        dropDown.Items.Add(new RadMenuItem("Item 2")); 
        dropDown.Items.Add(new RadMenuItem("Item 3")); 
        this.Children.Add(dropDown); 
 
        dropDown.Items[0].Click += new EventHandler(DropDownCellElement_Click); 
    } 
 
    void DropDownCellElement_Click(object sender, EventArgs e) 
    { 
        MessageBox.Show("Item clicked!"); 
    } 

I hope this helps. Should you have any other questions, don't hesitate to ask.

All the best,
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.
0
[Nean]
Top achievements
Rank 1
answered on 30 Jul 2009, 12:18 PM
Hi Jack,

Thanks! It seems to be what I was looking for... I will try it as soon as possible.

Regards,

[Nean]
0
[Nean]
Top achievements
Rank 1
answered on 30 Jul 2009, 12:56 PM

Sorry, I already have a question.
How can I intercept the DropDownCellElement_Click event from the form where is my RadGrid ?
Because I want to use this element in different grids, and the actions are different between the grids. Sio i want to intercept the click event on a menu item on my form and do whate I need to do according to wich item is clicked.

Regards,

[Nean]
0
Jack
Telerik team
answered on 31 Jul 2009, 02:11 PM
Hello [Nean],

You can pass the event handler as an argument when creating the cell. Check this sample:

void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)  
{  
    GridViewDataColumn column = e.Column as GridViewDataColumn;  
    if (column != null && column.UniqueName == "A" && e.Row is GridDataRowElement)  
    { 
        e.CellElement = new DropDownCellElement(e.Column, e.Row, new EventHandler(dropDownClicked)); 
    }  
 
private void dropDownClicked(object sender, EventArgs e) 
    MessageBox.Show("Clicked!"); 
 
public class DropDownCellElement : GridDataCellElement  
{  
    RadDropDownButtonElement dropDown; 
    EventHandler clickEvent; 
 
    public DropDownCellElement(GridViewColumn column, GridRowElement row, EventHandler clickEvent)  
        : base(column, row)  
    { 
        this.clickEvent = clickEvent; 
    }  
  
    protected override void CreateChildElements()  
    {  
        base.CreateChildElements();  
        dropDown = new RadDropDownButtonElement();  
        dropDown.Text = "DropDown";  
        dropDown.Items.Add(new RadMenuItem("Item 1"));  
        dropDown.Items.Add(new RadMenuItem("Item 2"));  
        dropDown.Items.Add(new RadMenuItem("Item 3"));  
        this.Children.Add(dropDown); 
 
        foreach (RadMenuItem item in dropDown.Items) 
        { 
            item.Click += new EventHandler(DropDownCellElement_Click); 
        } 
    }  
  
    void DropDownCellElement_Click(object sender, EventArgs e)  
    { 
        if (clickEvent != null
        { 
            clickEvent(sender, e); 
        } 
    }  
}  

If you have more questions, 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.
0
Mateo
Top achievements
Rank 1
answered on 09 Sep 2009, 02:46 PM
This example is nice but not very usefull in a way. 
Let's say i have a grid with lots of rows but only 10 visible rows at a time. Then 10 DropDownCells will be created and reused for the rest of the rows. Now let's say i want to be able to do some actions depending on the values of a DataBoundItem, then the drop down would have to be rebuild when a dropdowncell is assigned to a new row.

My DropDownCellElement is like this

public class DropDownCellElement : GridDataCellElement    
{    
    RadDropDownButtonElement dropDown;  
 
    public DropDownCellElement(GridViewColumn column, GridRowElement row)  
        : base(column, row)    
    {  
        dropDown = new RadDropDownButtonElement();  
    }    
    
    protected override void CreateChildElements()    
    {    
        base.CreateChildElements();    
        this.Children.Add(dropDown);    
    }  
 
    public RadDropDownButtonElement DropDown  
    {  
        get { return dropDown; }  
    }  
}   

It contains an empty DropDown that i want to build depending on a DataBoundItem of a row.
I've tried handling this in RowFormatting, CellFormatting but these events are triggered non stop and it doesn't work, the click is not fired for the items of the dropdown that i'm building. 
Where can i create this DropDown depending on the values of the DataBoundItem bound to the cellElement ?

thanks
Mateo
0
Jack
Telerik team
answered on 11 Sep 2009, 01:14 PM
Hi Mathieu Tanguay,

A good place is SetContent method of GridDataCellElement. It is executed when the cell value is changed (because the cell is reused, for example). Please tell us whether this event is suitable for you solution. We will be glad to assist you further.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Mateo
Top achievements
Rank 1
answered on 11 Sep 2009, 03:28 PM
I'm posting what seem's to work for me.

here is my custom cellElement class


public class DropDownCellElement : GridDataCellElement    
{    
    RadDropDownButtonElement dropDown;  
    public delegate void SetCellContentEventHandler(DropDownCellElement dropDownCell);  
    public event SetCellContentEventHandler SetCellContent;  
 
    public DropDownCellElement(GridViewColumn column, GridRowElement row)  
        : base(column, row)    
    {  
        dropDown = new RadDropDownButtonElement();  
    }    
    
    protected override void CreateChildElements()    
    {    
        base.CreateChildElements();    
        this.Children.Add(dropDown);    
    }  
 
    public RadDropDownButtonElement DropDown  
    {  
        get { return dropDown; }  
    }  
 
    public override void SetContent()  
    {  
        base.SetContent();  
        dropDown.Items.Clear();  
        if (SetCellContent != null)  
            SetCellContent(this);  
    }  
}   

I create the cells like this

  void grdDocuments_CreateCell(object sender, GridViewCreateCellEventArgs e)  
        {  
            GridViewDataColumn column = e.Column as GridViewDataColumn;  
            if (column != null && column.UniqueName.CompareTo("action") == 0 && e.Row is GridDataRowElement)  
            {  
                DropDownCellElement dd = new DropDownCellElement(e.Column, e.Row);  
                dd.SetCellContent += new DropDownCellElement.SetCellContentEventHandler(grdDocuments_DropDownCell_SetContent);  
                dd.DropDown.Text = Resources.CONTROLDATA_DOCGRID_BTN_ACTION;  
                dd.Click += new EventHandler(ReportStatusManualChange_Click);  
                e.CellElement = dd;  
            }  
        } 

and in the event handler i do what is necessary

void grdDocuments_DropDownCell_SetContent(DropDownCellElement dropDownCell)  
        {  
            Report report = (dropDownCell.Parent as GridDataRowElement).RowInfo.DataBoundItem as Report;  
 
            ControlData cd = GetSelectedControlData();  
            if (cd == null || report == null)  
                return;  
 
            if (ControlDataController.CanSendDocument(cd, report))  
            {  
                RadMenuItem i = new RadMenuItem();  
                i.Text = Resources.CONTROLDATA_DOCGRID_BTN_SEND;  
                i.Click += new EventHandler(grdDocuments_CommandCellClick);  
                dropDownCell.DropDown.Items.Add(i);  
            }  
 
            if (!string.IsNullOrEmpty(report.Path))  
            {  
                RadMenuItem view = new RadMenuItem();  
                view.Text = Resources.CONTROLDATA_DOCGRID_VIEWREPORT;  
                view.Tag = report;  
                view.Click += new EventHandler(ViewDocument_Click);  
                dropDownCell.DropDown.Items.Add(view);  
            }  
 
            if (!string.IsNullOrEmpty(report.Remarks))  
            {  
                RadMenuItem viewRemark = new RadMenuItem();  
                viewRemark.Text = Resources.CONTROLDATA_DOCGRID_VIEWREMARKS;  
                viewRemark.Tag = report;  
                viewRemark.Click += new EventHandler(ViewDocumentRemark_Click);  
                dropDownCell.DropDown.Items.Add(viewRemark);  
            }  
 
            List<Transat.Contract.TS.DocStatus> possibleStatus = ReportManager.GetPossibleManualStatusTransition(report, cd.FlightPattern);  
 
            if (possibleStatus.Count > 0)  
            {  
                RadMenuItem itemStatusChange = new RadMenuItem("Changer le Statut");  
                dropDownCell.DropDown.Items.Add(itemStatusChange);  
 
                foreach (Transat.Contract.TS.DocStatus ds in possibleStatus)  
                {  
                    RadMenuItem item = new RadMenuItem();  
                    item.Text = Utility.GetEnumDescription(ds);  
                    item.Click += new EventHandler(ReportStatusManualChange_Click);  
                    item.Tag = ds;  
                    itemStatusChange.Items.Add(item);  
                }  
            }  
 
            dropDownCell.Enabled = dropDownCell.DropDown.Items.Count > 0 ? true : false;  
        } 


It seem's to work just fine, i will test it more today.
Thanks for your help
mateo

0
Jack
Telerik team
answered on 14 Sep 2009, 02:39 PM
Hi Mateo, thank you for sharing your solution with the community. If you have any further questions, we will be glad to help you.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Mark
Top achievements
Rank 1
Answers by
Nick
Telerik team
[Nean]
Top achievements
Rank 1
Jack
Telerik team
Mateo
Top achievements
Rank 1
Share this question
or