Modify columns in GridView with Condition

3 posts, 0 answers
  1. Jacky
    Jacky avatar
    2 posts
    Member since:
    Jun 2014

    Posted 18 Jun 2014 Link to this post

    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. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3167 posts

    Posted 23 Jun 2014 Link to this post

    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.
     
  3. Jacky
    Jacky avatar
    2 posts
    Member since:
    Jun 2014

    Posted 24 Jun 2014 Link to this post

    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
Back to Top