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

Update Command Cell After Click

5 Answers 29 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Роберт
Top achievements
Rank 1
Роберт asked on 15 Oct 2016, 08:32 AM
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";
            }
        }
    }
}

 

 

 

5 Answers, 1 is accepted

Sort by
0
Роберт
Top achievements
Rank 1
answered on 15 Oct 2016, 11:19 PM
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..
0
Роберт
Top achievements
Rank 1
answered on 16 Oct 2016, 05:48 AM
How to change the current cell?
0
Роберт
Top achievements
Rank 1
answered on 16 Oct 2016, 06:12 AM

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";
            }
        }
    }
}
0
Accepted
Hristo
Telerik team
answered on 17 Oct 2016, 07:08 AM
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.
0
Hristo
Telerik team
answered on 17 Oct 2016, 07:09 AM
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.
Tags
GridView
Asked by
Роберт
Top achievements
Rank 1
Answers by
Роберт
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or