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