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

child view template /command button field

3 Answers 251 Views
GridView
This is a migrated thread and some comments may be shown as answers.
dev
Top achievements
Rank 1
dev asked on 05 Oct 2010, 11:34 AM
Hi all,

I have created the winforms  radgridview with tabbed child view , in one of the gridview template i want to add the command button field column programatically , while clicking button i have to catch the events and perform some operation ..

 please assist me to acheive that ..

waiting for ur reply.....

Thanks
Dev...

3 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 05 Oct 2010, 01:37 PM
Hello Dev,

I'm guessing you already know how to create a template for the grid, or you can follow the following example:

GridViewTemplate childTemplate = new GridViewTemplate();
childTemplate.DataSource = null; // set data source for the template here
 
// Creating the command column here
var commandColumn = new GridViewCommandColumn("Command");
childTemplate.Columns.Add(commandColumn);
 
GridViewRelation relation = new GridViewRelation(this.radGridView1.MasterTemplate);
relation.ChildTemplate = childTemplate;
relation.RelationName = "ParentChild";
relation.ParentColumnNames.Add("ID2");
relation.ChildColumnNames.Add("ID");
this.radGridView1.Relations.Add(relation);
childTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
childTemplate.BestFitColumns();
childTemplate.Caption = "ChildTemplate";
this.radGridView1.MasterTemplate.Templates.Add(childTemplate);

After that to catch the command column click event you should handle the CommandCellClick event, It fires every time when a command button is clicked. The sender argument contains the clicked cell. Here is a sample:
void radGridView1_CommandCellClick(object sender, EventArgs e)
{
    GridCommandCellElement cell = (GridCommandCellElement)sender;
    //...
}

And if you want to disable some command buttons you should You should handle CellFormatting event and set the Enabled property of the button:

void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    GridViewDataColumn column = e.CellElement.ColumnInfo as GridViewDataColumn;
    if (column != null && column.Name == "CommandColumnName")
    {
        GridCommandCellElement cell = (GridCommandCellElement)e.CellElement;
        if (cell.RowInfo.Cells["Value"].Value == null)
        {
            cell.CommandButton.Enabled = false;
        }
        else
        {
            cell.CommandButton.Enabled =(int)cell.RowInfo.Cells["Value"].Value > 10;
        }
    }
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
deva subramanian
Top achievements
Rank 1
answered on 26 Apr 2011, 11:53 AM
Hi Emanual,

Thanks for your previous reply its working fine. could you tell me how to give vertical /horizontal scroll bar for the childtemplates inside the main radgridview .. waiting for your reply
..

Thanks
Dev..
0
Emanuel Varga
Top achievements
Rank 1
answered on 29 Apr 2011, 11:15 AM
Hello,

Sorry for the very late response,

Horizontal scroll bars appear only if fill option is not specified for the child template, more specifically just remove this line:
childTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

For the vertical scroll bars to appear please take a look at this help article, or this thread

Best Regards,
Emanuel Varga

WinForms MVP
Tags
GridView
Asked by
dev
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
deva subramanian
Top achievements
Rank 1
Share this question
or