public void OnAddProp(string label, string codeBehind, int rowIndex = -1)
    {
        if (rowIndex == -1 && _propertyControlGrid.SelectedCells.Count == 0)
        {
            return;
        }
        var rowIndexVal = rowIndex >= 0
            ? rowIndex
            : _propertyControlGrid.SelectedCells[0].RowIndex;

        var theRow = _propertyControlGrid.Rows[rowIndexVal];

        theRow.Cells[0].Value = label;
        theRow.Cells[1].Value = "";

        var newBoundItem = new PropertyBoundItem(label, codeBehind);

        if (!_propMapData.ContainsKey(theRow.Index))
        {
            _propMapData.Add(theRow.Index, newBoundItem);
        }
        else
        {
            _propMapData[theRow.Index] = newBoundItem;
        }

        if (label == "" && codeBehind == "")
        {
            _propMapData.Remove(theRow.Index);
        }
    }
    void _enablePropUpdate_CheckStateChanged(object sender, EventArgs e)
    {
        if (!_enablePropUpdate.Checked)
        {
            // Unchecked means must be recompiled
            foreach (var key in _propMapData.Keys)
            {
                PropertyBoundItem propertyBoundItem = _propMapData[key];

                // Submit for compile/run
                propertyBoundItem.CompileHandle = null;
            }
        }
    }
    private void updatePropertiesGrid()
    {
        if (_propMapData.Count == 0)
        {
            return;
        }

        //   StringBuilder sb = new StringBuilder();
        foreach (var key in _propMapData.Keys)
        {
            PropertyBoundItem propertyBoundItem = _propMapData[key];

            // Submit for compile/run
            if (propertyBoundItem.CompileHandle == null)
            {
                string errorText;
                propertyBoundItem.CompileHandle = CSCompile.DoCompile(propertyBoundItem.CodeBehind, out errorText);

                if (errorText != null)
                {
                    SetProp(key, "Compile Fail - See Output for Details");
                    _outputText.Text = errorText;
                    propertyBoundItem.CompileHandle = null;
                    continue;
                }
                else
                {
                    _outputText.Text = "Compiled Successfully";
                }
            }

            try
            {
                propertyBoundItem.RunResults = CSCompile.DoRun(propertyBoundItem.CompileHandle);
                SetProp(key, propertyBoundItem.RunResults);
            }
            catch (Exception ex)
            {
                SetProp(key, "Code Execution Fail on Row " + key + " - See Output for Details");
                _outputText.Text = ex.ToString();
            }
        }
        _propertyControlGrid.ClearSelection();
        _propertyControlGrid.Refresh();
    }
    public void OnAddProp(string label, string codeBehind, int rowIndex = -1)
    {
        if (rowIndex == -1 && _propertyControlGrid.SelectedCells.Count == 0)
            return;
        var rowIndexVal = rowIndex >= 0
            ? rowIndex
            : _propertyControlGrid.SelectedCells[0].RowIndex;

        var theRow = _propertyControlGrid.Rows[rowIndexVal];

        theRow.Cells[0].Value = label;
        theRow.Cells[1].Value = "";

        var newBoundItem = new PropertyBoundItem(label, codeBehind);

        if (!_propMapData.ContainsKey(theRow.Index))
            _propMapData.Add(theRow.Index, newBoundItem);
        else
        {
            _propMapData[theRow.Index] = newBoundItem;
        }

        if (label == "" && codeBehind == "")
            _propMapData.Remove(theRow.Index);
    }