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

Modify columns in GridView with Condition

2 Answers 167 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jacky
Top achievements
Rank 1
Jacky asked on 18 Jun 2014, 03:38 PM
For C# winforms.
I wanted to check for each cells in a RadGridView. Wanted to add a eventhandler, once all data dataloaded.
For the cell with value "Completed" I would like to change the cell into a button, lets say a radButton named "radButtonView".

Anyone have any idea how to do that?
A simple example will do :)

2 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Jun 2014, 12:13 PM
Hello Jacky,

Thank you for writing.

If I understand your requirement correctly, you are trying to display a RadButton inside a cell under some circumstances. For this purpose it is suitable to use a GridViewCommandColumn which cells have button by default. Afterwards, you can use the CellFormatting event and hide the button according to your custom conditions.
public Form1()
{
    InitializeComponent();
    for (int i = 0; i < 10; i++)
    {
        this.radGridView1.Rows.Add(i, DateTime.Now.AddDays(i), "Row" + i);
        if (i % 2 == 0)
        {
            this.radGridView1.Rows.Last().Tag = "Completed";
        }
    }
    this.radGridView1.MasterTemplate.Refresh();
}
 
private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    GridCommandCellElement commandCell = e.CellElement as GridCommandCellElement;
    if (commandCell != null)
    {
        if (e.Row.Tag == "Completed")
        {
            commandCell.CommandButton.Visibility = Telerik.WinControls.ElementVisibility.Visible;
        }
        else
        {
            commandCell.CommandButton.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
        }
    }
}

If it is not the exact requirement please specify in details what is the expected design.

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Jacky
Top achievements
Rank 1
answered on 24 Jun 2014, 01:21 PM
Hi Desislava,

Thanks for the sample resolution.
The issue is quite urgent and it is resolved by adding expression to the column.
Still glad to try out the sample given by you. Thanks :)

Kind regards,
Jacky
Tags
GridView
Asked by
Jacky
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Jacky
Top achievements
Rank 1
Share this question
or