ComboBox not updating cell vallue

We are trying to use a ComboBox in a column to select from a list of values. The ComboBox appears correctly and the items in the ComboBox are correct, but after the user makes a selection, the underlying cell value does not change. When we use the arrow keys and we move between ComboBox cells, the value in the ComboBox appears to be correct. But after the ComboBox dissappears and we see the underlying cell value, it remains as the old value.

Here is the relevant code:

private void PatientViewMetro_Cases_Shown(object sender, EventArgs e) {
            // Callbacks
            this.gridGroupingControlCases.RecordValueChanged += gridGroupingControlCases_RecordValueChanged;
            this.gridGroupingControlCases.TableControlCurrentCellCloseDropDown += gridGroupingControlCases_TableControlCurrentCellCloseDropDown;
            this.gridGroupingControlCases.TableControlCurrentCellValidating += gridGroupingControlCases_TableControlCurrentCellValidating;

            // Load the Context
            context.Cases
                .Where(c => c.Patient_Id == patient.Id)
                .Include(p => p.Goals)
                .Load();
            context.Providers
                .Where(p => p.IsProvider == true)
                .Load();

            // Cases
            bindingSourceCases.DataSource = context.Cases.Local.ToBindingList();
            this.gridGroupingControlCases.DataSource = bindingSourceCases;
            bindingSourceCases.ResetBindings(false);
            bindingSourceCases.AddingNew += bindingSourceCases_AddingNew;
            bindingSourceCases.ListChanged += bindingSourceCases_ListChanged;

            // Goals
            bindingSourceGoals.DataSource = context.Goals.Local.ToBindingList();
            this.gridGroupingControlCases.Engine.SourceListSet.Add("Goals", bindingSourceGoals);
            bindingSourceGoals.ResetBindings(false);
            bindingSourceGoals.AddingNew += bindingSourceGoals_AddingNew;
            bindingSourceGoals.ListChanged += bindingSourceGoals_ListChanged;

            // Case-Goals Relation
            this.gridGroupingControlCases.TableDescriptor.Relations.Clear();
            GridRelationDescriptor relation = new GridRelationDescriptor();
            relation.Name = "Goal";
            relation.ChildTableName = "Goals";
            relation.RelationKind = Syncfusion.Grouping.RelationKind.RelatedMasterDetails;
            relation.RelationKeys.Add("Id", "Case_Id");
            this.gridGroupingControlCases.TableDescriptor.Relations.Add(relation);

            this.gridGroupingControlCases.GridOfficeScrollBars = Syncfusion.Windows.Forms.OfficeScrollBars.Metro;
            this.gridGroupingControlCases.GridVisualStyles = Syncfusion.Windows.Forms.GridVisualStyles.Metro;
            this.gridGroupingControlCases.TopLevelGroupOptions.ShowAddNewRecordBeforeDetails = true;
            this.gridGroupingControlCases.TopLevelGroupOptions.ShowAddNewRecordAfterDetails = false;
            this.gridGroupingControlCases.NestedTableGroupOptions.ShowAddNewRecordBeforeDetails = true;
            this.gridGroupingControlCases.NestedTableGroupOptions.ShowAddNewRecordAfterDetails = false;
            gridGroupingControlCases.TableDescriptor.AllowNew = true;
            gridGroupingControlCases.TableDescriptor.AllowEdit = true;
            this.gridGroupingControlCases.TableControl.CurrentCell.ShowErrorIcon = true;
            this.gridGroupingControlCases.TableControl.ShowRowHeaderErroricon = true;

            //this.gridGroupingControl1.SetMetroStyle(System.Drawing.Color.DarkViolet);
            Dictionary<string, string> visibleCaseColumns = new Dictionary<string, string>() {
                { "Name", "Name" },
                { "Description", "Description" },
                { "Provider_FullName", "Assigned Provider" },
                { "DxCode1_DxCodeString", "Dx Code 1" },
                { "DxCode2_DxCodeString", "Dx Code 2" },
                { "DxCode3_DxCodeString", "Dx Code 3" },
                { "DxCode4_DxCodeString", "Dx Code 4" },
                { "DxCode5_DxCodeString", "Dx Code 5" },
            };
            Dictionary<string, string> visibleGoalColumns = new Dictionary<string, string> {
                { "Description", "Description" },
                { "Metric", "Metric" },
                { "EffectiveDate", "Effective Date" },
                { "TerminationDate", "Termination Date" },
            };
            int i = 0;
            foreach (var column in this.gridGroupingControlCases.TableDescriptor.Columns.Clone()) {
                if (!visibleCaseColumns.Keys.Contains(column.Name))
                    this.gridGroupingControlCases.TableDescriptor.Columns.Remove(column.Name);
                else {
                    this.gridGroupingControlCases.TableDescriptor.Columns[column.Name].HeaderText = visibleCaseColumns[column.Name];
                }
            }
            foreach (var column in this.gridGroupingControlCases.TableDescriptor.Relations[0].ChildTableDescriptor.Columns.Clone()) {
                if (!visibleGoalColumns.Keys.Contains(column.Name))
                    this.gridGroupingControlCases.TableDescriptor.Relations[0].ChildTableDescriptor.Columns.Remove(column.Name);
                else this.gridGroupingControlCases.TableDescriptor.Relations[0].ChildTableDescriptor.Columns[column.Name].HeaderText = visibleGoalColumns[column.Name];
            }

            GridTableCellStyleInfo ggcStyle = this.gridGroupingControlCases.TableDescriptor.Columns["Provider_FullName"].Appearance.AnyRecordFieldCell;
            ggcStyle.CellType = GridCellTypeName.ComboBox;
            ggcStyle.DataSource = context.Providers.Local.ToBindingList();
            ggcStyle.ValueMember = "Id";
            ggcStyle.DisplayMember = "FullName";
}

private void gridGroupingControlCases_TableControlCurrentCellCloseDropDown(object sender, GridTableControlPopupClosedEventArgs e) {
            //To get the ComboBox cell renderer  
            GridComboBoxCellRenderer renderer = this.gridGroupingControlCases.TableControl.CurrentCell.Renderer as GridComboBoxCellRenderer;
            if (renderer != null) {
                int providerId = Convert.ToInt32(renderer.ControlValue);
                var currentCell = this.gridGroupingControlCases.TableControl.CurrentCell;

                Provider provider = context.Providers
                    .Local
                    .Where(p => p.Id == providerId).FirstOrDefault();

                Case currentCase = (Case)this.gridGroupingControlCases.Table.CurrentRecord.GetData();
                currentCase.Provider = provider;

                currentCell.Renderer.ControlText = provider.FullName;
                //currentCell.Curr
                renderer.UpdateControlValue();
            }
}

Thanks in advance,
John

6 Replies

PM Piruthiviraj Malaimelraj Syncfusion Team January 16, 2018 11:47 AM UTC

Hi John, 

Thanks for contacting Syncfusion support. 

We have analyzed your reported scenario and given code snippet. In order to update the cell value when combobox selection has changed, set the text as you want to TextBox of GridComboBoxCellRenderer instead of using ControlText. Please make use of the below code and let us know if you have any other queries, 

Code snippet: 
void gridGroupingControl1_TableControlCurrentCellCloseDropDown(object sender, GridTableControlPopupClosedEventArgs e) 
{ 
    GridComboBoxCellRenderer renderer = this.gridGroupingControl1.TableControl.CurrentCell.Renderer as GridComboBoxCellRenderer; 
    if (renderer != null) 
    { 
        renderer.TextBox.Text = "SampleText"; 
    } 
} 

Regards, 
Piruthiviraj 



JY John Yost January 16, 2018 05:46 PM UTC

Thank for you the suggestion. Unfortunately it only half works.
I have updated my TableControlCurrentCellCloseDown method to the code below.
Now, the gridGroupingControl shows the correct value until the user changes rows. For example, if the user clicks the cell (currently showing a value of "A"), the combobox appears. The user selects "B" from the list, for example, and the combobox collapses leaving "B" in the cell. However, when the user clicks on a different row the value goes back to the original value of "B". The new value does not persist in the cell.

Here is my updated TableControlCurrentCellCloseDown callback:

private void gridGroupingControlCases_TableControlCurrentCellCloseDropDown(object sender, GridTableControlPopupClosedEventArgs e) {
            // Get the ComboBox cell renderer  
            GridComboBoxCellRenderer renderer = this.gridGroupingControlCases.TableControl.CurrentCell.Renderer as GridComboBoxCellRenderer;
            if (renderer != null) {
                int providerId = Convert.ToInt32(renderer.ControlValue);
                var currentCell = this.gridGroupingControlCases.TableControl.CurrentCell;

                // Update the local collection
                Provider provider = context.Providers
                    .Local
                    .Where(p => p.Id == providerId).FirstOrDefault();

                Case caseData = (Case)this.gridGroupingControlCases.Table.CurrentRecord.GetData();
                Case currentCase = context.Cases.Local
                    .Where(c => c.Id == caseData.Id).FirstOrDefault();
                currentCase.Provider = provider;

                renderer.TextBox.Text = provider.FullName; // your suggestion...
            }
}


JY John Yost January 17, 2018 12:47 AM UTC

I finally found the missing piece:

this.gridGroupingControlCases.Refresh();

After I added this line, the cell value sticks after the drop-down closes AND after you move to a different row.

Thanks for the help.


AR Arulpriya Ramalingam Syncfusion Team January 17, 2018 05:12 AM UTC

Hi John, 
 
Thanks for your update.    
 
Please let us know if you have any other queries.    
   
Regards, 
Arulpriya 



JY John Yost March 5, 2018 07:23 PM UTC

Actually, I ran into this issue again. For some reason the solution stopped working again. Fortunately this time I managed to find the right solution from another post.

Again, the problem was, when using a combobox in the GridGroupingControl, the selection was not updating when the user would change rows. The user would click the comboBox, click an item in the coboBox, I would update the datasource, then after the comboBox collapsed, the value in the cell would NOT have changed. It would still show the old value when the user moved to a different row.

Anyway, for others, the solution was to mark the table as 'dirty':
this.gridGroupingControlCases.Table.TableDirty = true;

I hope this helps someone else because I've spent over three solid days collectively on this issue.


AR Arulpriya Ramalingam Syncfusion Team March 6, 2018 06:05 AM UTC

Hi John, 
 
We are glad that the reported scenario was resolved at your end. 
 
As per your update, the TableDirty can be enabled to update the cell contents dynamically. If a table is marked dirty, any subsequent access to child elements will trigger and re-categorization of all records in the table will be enabled. 
 
Please let us know, if you have any other queries. 
 
Regards, 
Arulpriya 


Loader.
Up arrow icon