private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { e.Handled = true; List <DataGridViewRow> list = dataGridView1.ToList().Where(x => x.Cells[0].Value != null).ToList(); var variables = list.ToDictionary(x => ((string)x.Cells[0].Value)[0], x => ParseExpression.Parse((string)x.Cells[1].Value, null)); var bindings = variables.ToDictionary(x => x.Key, x => (IExpression <double>) new Variable(x.Key, variables)); var expr = ParseExpression.Parse(textBox1.Text, bindings); listBox1.Items.Add(textBox1.Text + ": " + expr.Evaluate()); textBox1.Clear(); } }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { if (listBox1.SelectedIndex < 0) { return; } List <DataGridViewRow> list = dataGridView1.ToList().Where(x => x.Cells[0].Value != null).ToList(); var variables = list.ToDictionary(x => ((string)x.Cells[0].Value)[0], x => ParseExpression.Parse((string)x.Cells[1].Value, null)); var bindings = variables.ToDictionary(x => x.Key, x => (IExpression <double>) new Variable(x.Key, variables)); var expr = ParseExpression.Parse((string)listBox1.SelectedItem.ToString().Split(':')[0], bindings); treeView1.Nodes.Clear(); treeView1.Nodes.Add(NodeFromExpr(expr)); }