private void LoadSchemaControl_Click(object sender, EventArgs e) { frmVariableSelector selectionForm = new frmVariableSelector(); selectionForm.Text = "Load Schema"; selectionForm.lblHeader.Text = "Select a DataTable from the list"; foreach (var item in _dataTableCreationCommands) { selectionForm.lstVariables.Items.Add(item.v_OutputUserVariableName); } var result = selectionForm.ShowDialog(); if (result == DialogResult.OK) { var tableName = selectionForm.lstVariables.SelectedItem.ToString(); var schema = _dataTableCreationCommands.Where(f => f.v_OutputUserVariableName == tableName).FirstOrDefault(); v_DataRowDataTable.Rows.Clear(); foreach (DataRow rw in schema.v_ColumnNameDataTable.Rows) { v_DataRowDataTable.Rows.Add(rw.Field <string>("Column Name"), ""); } } }
public void ShowVariableSelector(object sender, EventArgs e) { //create variable selector form frmVariableSelector newVariableSelector = new frmVariableSelector(); //get copy of user variables and append system variables, then load to combobox var variableList = _currentEditor.ScriptVariables.Select(f => f.VariableName).ToList(); variableList.AddRange(Common.GenerateSystemVariables().Select(f => f.VariableName)); newVariableSelector.lstVariables.Items.AddRange(variableList.ToArray()); //if user pressed "OK" if (newVariableSelector.ShowDialog() == DialogResult.OK) { //ensure that a variable was actually selected if (newVariableSelector.lstVariables.SelectedItem == null) { //return out as nothing was selected MessageBox.Show("There were no variables selected!"); return; } //grab the referenced input assigned to the 'insert variable' button instance CommandItemControl inputBox = (CommandItemControl)sender; //currently variable insertion is only available for simply textboxes //load settings var settings = new ApplicationSettings().GetOrCreateApplicationSettings(); if (inputBox.Tag is TextBox) { TextBox targetTextbox = (TextBox)inputBox.Tag; //concat variable name with brackets [vVariable] as engine searches for the same targetTextbox.Text = targetTextbox.Text.Insert(targetTextbox.SelectionStart, string.Concat("{", newVariableSelector.lstVariables.SelectedItem.ToString(), "}")); } else if (inputBox.Tag is ComboBox) { ComboBox targetCombobox = (ComboBox)inputBox.Tag; //concat variable name with brackets [vVariable] as engine searches for the same targetCombobox.Text = targetCombobox.Text.Insert(targetCombobox.SelectionStart, string.Concat("{", newVariableSelector.lstVariables.SelectedItem.ToString(), "}")); } else if (inputBox.Tag is DataGridView) { DataGridView targetDGV = (DataGridView)inputBox.Tag; if (targetDGV.SelectedCells.Count == 0) { MessageBox.Show("Please make sure you have selected an action and selected a cell before attempting" + " to insert a variable!", "No Cell Found", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (targetDGV.SelectedCells[0].ColumnIndex == 0) { MessageBox.Show("Invalid Cell Selected!", "Invalid Cell Selected", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } targetDGV.SelectedCells[0].Value = targetDGV.SelectedCells[0].Value + string.Concat("{", newVariableSelector.lstVariables.SelectedItem.ToString(), "}"); //TODO - Insert variables at cursor position instead of at the end of a cell //targetDGV.CurrentCell = targetDGV.SelectedCells[0]; //targetDGV.BeginEdit(false); //TextBox editor = (TextBox)targetDGV.EditingControl; //editor.Text = editor.Text.Insert(editor.SelectionStart, string.Concat("{", // newVariableSelector.lstVariables.SelectedItem.ToString(), "}")); } } }