Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
40
WinGrid which even for updating Cell based on another changed cell value
posted

I have an updatable WinGrid with a dataset as datasource.

WinGrid.UpdateMode is set to OnRowChangeOrLostFocus

For ItemID and ItemDescription tyles are set to DropDownValidate and ValueList is taken from two different UltraCombo's (user is able to select only values from drop down)

I wouldl like to cover following scenario:

If user changed ItemID then I need to change ItemDescription programmatically.

If user changed ItemDescription then I need to change ItemID programmatically.

My code (for changing value in other cell) have to be executed only once (not on every keyboard stroke) and only if user changed value either in ItemID or ItemDescription but before any other cell changes and before changes from WinGrid will be submitted to datasource.

Which event will the best choice for that?

Parents
No Data
Reply
  • 2700
    Offline posted

    Hello,

    I have been looking into your question and created a small sample with a WinGrid that aims to replicate the described scenario.

    To achieve your requirement, my suggestion is to use the grid’s AfterCellUpdate event. It triggers multiple times, however, a simple boolean flag can be used in order not to execute the logic twice. The “updatedOnce” flag is initially false and is set to true if the value in one of the UltraCombos changes (using the UltraCombo’s ValueChanged event).

    For the purposes of the example, I am setting the modified “ItemID” or “ItemDescription” cell’s value to the value on the corresponding selected index in the other combo on the same row (i.e. “Id1” goes with “Description 1” and the other way around). 

    private void ultraGrid1_AfterCellUpdate(object sender, CellEventArgs e)
            {
                if (this.updatedOnce)
                {
                    IValueList vl1 = this.ultraCombo1;
                    IValueList vl2 = this.ultraCombo2;
     
                    if (e.Cell.Column == this.ultraGrid1.DisplayLayout.Bands[0].Columns["ItemID"])
                    {
                        UltraGridRow row = e.Cell.Row;
                        this.updatedOnce = false;
                        row.Cells["ItemDescription"].Value = vl2.GetText(vl1.SelectedItemIndex);
                    }
                    else if (e.Cell.Column == this.ultraGrid1.DisplayLayout.Bands[0].Columns["ItemDescription"])
                    {
                        UltraGridRow row = e.Cell.Row;
                        this.updatedOnce = false;
                        row.Cells["ItemID"].Value = vl1.GetText(vl2.SelectedItemIndex);
                    }
                }
            }

    Since changing the value programmatically triggers the event again, the flag is reset before the cell update, in order not to execute the same logic twice. The “ItemID” and “ItemDescription”’s modified cell’s value is synchronized before editing another cell and on losing focus.

    I have attached a sample application, that uses the approach from above. Please, test it on your side and if you require any further assistance on the matter, please let me know.

    Sincerely,

    Bozhidara Pachilova

    Associate Software Developer

    6708.UGCellUpdates.zip

Children