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();
}
}