// determine if we can set the selected column as the response variable /// (cannot set a transformed independent variable as the response variable - or categorical variables....) public bool canSetRV(Utilities utils) { bool colisT = dt.Columns[intSelectedColIndex].ExtendedProperties.ContainsKey(VBCommon.Globals.TRANSFORM); bool colisI = dt.Columns[intSelectedColIndex].ExtendedProperties.ContainsKey(VBCommon.Globals.OPERATION); bool colisCat = utils.testValueAttribute(dt.Columns[intSelectedColIndex], VBCommon.Globals.CATEGORICAL); if (colisT == true || colisCat == true) return false; else return true; }
// user click captured - decide what menu items are appropriate and show them public void showContextMenus(DataGridView dgv, MouseEventArgs me, DataTable dt) { dtColumnInformation dtCI = new dtColumnInformation(dt); Utilities utils = new Utilities(); DataGridView.HitTestInfo ht = dgv.HitTest(me.X, me.Y); int colndx = ht.ColumnIndex; int rowndx = ht.RowIndex; if (rowndx > 0 && colndx > 0) return; //cell hit, go away if (rowndx < 0 && colndx >= 0) { //col header hit, show proper menu intSelectedColIndex = colndx; //do nothing if col 0 selected if (colndx >= 1) { string colname = dt.Columns[colndx].Caption; if (colname == strResponseVarColName) { if (utils.testValueAttribute(dt.Columns[intResponseVarColIndex], VBCommon.Globals.DEPENDENTVAR)) { cmforResponseVar.MenuItems[0].Enabled = true; //we can transform a response variable } else { cmforResponseVar.MenuItems[0].Enabled = false; //but we cannot transform a transformed response } if (utils.testValueAttribute(dt.Columns[intResponseVarColIndex], VBCommon.Globals.DEPENDENTVARIBLETRANSFORM)) { cmforResponseVar.MenuItems[2].Enabled = true; //we can untransform the transformed response variable } else { cmforResponseVar.MenuItems[2].Enabled = false; //but cannot untransform a response variable } cmforResponseVar.Show(dgv, new Point(me.X, me.Y)); } else { //show context menu for ivs if (dtCI.getColStatus(dt.Columns[intSelectedColIndex].ColumnName.ToString())) { //here if col enabled cmforIVs.MenuItems[0].Enabled = true; cmforIVs.MenuItems[1].Enabled = false; //cannot enable enabled col cmforIVs.MenuItems[2].Enabled = true; //response variable must be a ME, T(RV) or I(IV) not created by general transform //if they do this then we're to remove all general operations performed, if (canSetRV(utils)) cmforIVs.MenuItems[2].Enabled = true; else cmforIVs.MenuItems[2].Enabled = false; if (dt.Columns[intSelectedColIndex].ExtendedProperties.ContainsKey(VBCommon.Globals.MAINEFFECT)) cmforIVs.MenuItems[4].Enabled = false; //cannot remove maineffect column else cmforIVs.MenuItems[4].Enabled = true; } else { //here if col disabled cmforIVs.MenuItems[0].Enabled = false; //cannot disable disabled col cmforIVs.MenuItems[1].Enabled = true; cmforIVs.MenuItems[2].Enabled = false; //cannot disabled the response variable } cmforIVs.Show(dgv, new Point(me.X, me.Y)); } } } else if (rowndx >= 0 && colndx < 0) { //row header hit, show menu intSelectedRowIndex = rowndx; if (dtRI.getRowStatus(dt.Rows[intSelectedRowIndex][0].ToString())) { //here if row is enabled cmforRows.MenuItems[0].Enabled = true; cmforRows.MenuItems[1].Enabled = false; //cannot enable enabled row } else { //here if row is disabled cmforRows.MenuItems[0].Enabled = false; //cannot disable disabled row cmforRows.MenuItems[1].Enabled = true; } cmforRows.Show(dgv, new Point(me.X, me.Y)); } }
//unpack event handler. unpacks packed state in dictionary to repopulate datasheet public void UnpackState(IDictionary<string, object> dictPackedState) { //unpack datatable this.DT = (DataTable)dictPackedState["DT"]; this.DT.TableName = "DataSheetData"; this.dgv.DataSource = null; this.dgv.DataSource = this.DT; //get row and column information this.DTRI = VBCommon.Metadata.dtRowInformation.getdtRI(this.DT, true); this.DTRI.DTRowInfo = (Dictionary<string, bool>)dictPackedState["DTRowInfo"]; this.DTCI = VBCommon.Metadata.dtColumnInformation.getdtCI(this.DT, true); this.DTCI.DTColInfo = (Dictionary<string, bool>)dictPackedState["DTColInfo"]; this.SelectedColIndex = (int)dictPackedState["CurrentColIndex"]; this.ResponseVarColName = (string)dictPackedState["DepVarColName"]; this.ResponseVarColIndex = this.DT.Columns.IndexOf(this.ResponseVarColName); //get validated flag this.boolValidated = (bool)dictPackedState["DSValidated"]; this.Utils = new VBCommon.Metadata.Utilities(); this.TableUtils = new VBCommon.Metadata.Utilities.TableUtils(this.DT); this.GridUtils = new VBCommon.Metadata.Utilities.GridUtils(this.dgv); this.GridUtils.maintainGrid(this.dgv, this.DT, this.SelectedColIndex, this.ResponseVarColName); //initial info for the list FileInfo fi = new FileInfo(Name); this.FileName = fi.Name; this.showListInfo(this.FileName, this.DT); if ((bool)dictPackedState["Clean"]) { this.State = VBCommon.Controls.DatasheetControl.dtState.clean; } else { this.State = VBCommon.Controls.DatasheetControl.dtState.dirty; } //if clean, initial pass is false //boolInitialPass = !(bool)dictPluginState["Clean"]; }