How to catch ESC (restore cell values)?

Originally Posted 21 September 2016, 10:04 am EST

  • Originally Posted 21 September 2016, 10:04 am EST

    Hi,
    For example: I have 2 columns which are both bound.
    Column1 contains a value of "1", and the value of column2 is "A".
    Now the user enters a value of "2" to column1, and the BeforeColUpdate event assigns a value of "ABC" to column2.
    All is OK.
    However, moving back to the cell of column1 and pressing ESC reverts the cell back to its original value of "1" (cancels the changes made to the current cell).
    I want the value of column2 to also revert back to "A".

    There is no event that fires when a cell is restored to its original value. I thought about using the KeyPress event to catch the ESC key, but then I don't know in this event the previous value of column1 because when I press ESC key, it will fire when column1 has the value of "2"
    before restoring it to a value of "1".

    What should I do?

    Thanks in advance.
  • Reply

    Hi,

    Please note, it is the design behavior of C1TrueDBGrid to revert value only for a single cell when user press ESC key. Therefore, it is not possible to achieve your requirement in C1TrueDBGrid.

    Thanks & Regards,
    Sonu Singh
  • Marked as Answer

    Reply

    Hi,

    We were trying to find out something to help you out and here it is:
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    var ds = new DataSet();
    var dt = new DataTable("table");
    dt.Columns.Add("First");
    dt.Columns.Add("Second");
    dt.Rows.Add(new object[] { 1, "A" });
    ds.Tables.Add(dt);
    c1TrueDBGrid1.SetDataBinding(ds, dt.TableName);

    c1TrueDBGrid1.ColEdit += c1TrueDBGrid1_ColEdit;
    c1TrueDBGrid1.KeyDown += Grid_KeyDown;
    }

    private void c1TrueDBGrid1_ColEdit(object sender, ColEventArgs e)
    {
    if (c1TrueDBGrid1.Col == 0)
    {
    c1TrueDBGrid1.Columns[1].Value = "ABC";
    }
    }

    private void Grid_KeyDown(object sender, KeyEventArgs e)
    {
    var grid = sender as C1TrueDBGrid;
    if (e.KeyData == Keys.Escape && grid.Columns[0].DataChanged)
    {
    grid.DataChanged = false;
    }
    }
    }

    Please refer to the attached sample application implementing the same.

    Thanks,
    Akshay
    2016/09/prj_RestoreCellValues_works.zip
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels