Update Command Cell After Click

6 posts, 1 answers
  1. Robert
    Robert avatar
    53 posts
    Member since:
    Feb 2010

    Posted 15 Oct Link to this post

    Problem:
    What should be done to force the Command button to change its content right away, without changing the focus to other cell?

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
     
    namespace GridApp
    {
        public partial class RadForm1 : Telerik.WinControls.UI.RadForm
        {
            public RadForm1()
            {
                InitializeComponent();
                radGridView1.Rows.Add(new object[1] { "zero" });
                radGridView1.Rows.Add(new object[1] { "one" });
                radGridView1.Rows.Add(new object[1] { "two" });
                radGridView1.Rows.Add(new object[1] { "three" });
                radGridView1.Rows.Add(new object[1] { "four" });
            }
     
            private void radGridView1_CommandCellClick(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
            {
                switch (e.ColumnIndex)
                {
                    case 1:
                        RadButtonElement b = (RadButtonElement)((GridCellElement)radGridView1.CurrentCell).Children[0];
                        b.Tag = true ^ (bool)b.Tag;
                        break;
                    default:
                        break;
                }
            }
     
            private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
            {
                if (e.ColumnIndex == 1)
                {
                    RadButtonElement b = (RadButtonElement)e.CellElement.Children[0];
                    b.ImageAlignment = ContentAlignment.MiddleCenter;
                    b.TextAlignment = ContentAlignment.MiddleCenter;
                    // set bool data as switch
                    if (b.Tag == null) b.Tag = false;
                    b.Text = ((bool)b.Tag) ? "locked" : "open";
                }
            }
        }
    }

     

     

     

  2. Robert
    Robert avatar
    53 posts
    Member since:
    Feb 2010

    Posted 15 Oct in reply to Robert Link to this post

    All changes happen only after the cell is validated.
    In other words: how to validate a cell manually?
    I can't find Cell.Validate() command..
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Robert
    Robert avatar
    53 posts
    Member since:
    Feb 2010

    Posted 16 Oct in reply to Robert Link to this post

    How to change the current cell?
  5. Robert
    Robert avatar
    53 posts
    Member since:
    Feb 2010

    Posted 16 Oct Link to this post

    Yes, done.. handy stuff

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
     
    namespace GridApp
    {
        public partial class RadForm1 : Telerik.WinControls.UI.RadForm
        {
            public RadForm1()
            {
                InitializeComponent();
                radGridView1.Rows.Add(new object[1] { "zero" });
                radGridView1.Rows.Add(new object[1] { "one" });
                radGridView1.Rows.Add(new object[1] { "two" });
                radGridView1.Rows.Add(new object[1] { "three" });
                radGridView1.Rows.Add(new object[1] { "four" });
                radGridView1.Columns[0].HeaderText = "ID";
                radGridView1.Columns[1].HeaderText = "COMMAND";
            }
     
            private void radGridView1_CommandCellClick(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
            {
                switch (e.ColumnIndex)
                {
                    case 1:
                        if (!DoYourActivityHere(radGridView1.Rows[e.RowIndex].Cells[0].Value)) return;
                        RadButtonElement b = (RadButtonElement)((GridCellElement)radGridView1.CurrentCell).Children[0];
                        b.Tag = true ^ (bool)b.Tag;
                        // trick: double set to make sure it's validated
                        radGridView1.GridNavigator.Select(radGridView1.Rows[e.RowIndex], radGridView1.Columns[0]);
                        radGridView1.GridNavigator.Select(radGridView1.Rows[e.RowIndex], radGridView1.Columns[1]);
                        break;
                    default:
                        break;
                }
            }
     
            bool DoYourActivityHere(object ID)
            {
                // I have trigger here TRUE/FALSE
                //  in your case you can consider many different states of result
                // then depending on the result state, show text or icon
                // on Command cell button, indicating the result
                return true;
            }
            private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
            {
                if (e.ColumnIndex == 1)
                {
                    RadButtonElement b = (RadButtonElement)e.CellElement.Children[0];
                    if (b.Tag == null) b.Tag = false;
                    b.ImageAlignment = ContentAlignment.MiddleCenter;
                    //b.Image = ((bool)b.Tag) ? GridApp.Properties.Resources.locked : GridApp.Properties.Resources.lock_open;
                    b.Text = ((bool)b.Tag) ? "locked" : "open";
                }
            }
        }
    }
  6. Answer
    Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 17 Oct Link to this post

    Hi Vitali,

    Thank you for writing.

    I am glad that you have managed to resolve the question.

    Please let me know if you need further assistance.

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
  7. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 17 Oct Link to this post

    Hi Vitali,

    Thank you for writing.

    I am glad that you have managed to resolve the question.

    Please let me know if you need further assistance.

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready