Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How can i get a string value from a datagrid cell?
- public partial class MainWindow : Window
- {
- ObservableCollection<DataCell> spreadsheet = new ObservableCollection<DataCell>();
- public MainWindow()
- {
- //Communal Spreadsheet
- InitializeComponent();
- spreadsheet.Add(new DataCell("", "", "", "", "", ""));
- spreadsheet.Add(new DataCell("", "", "", "", "", ""));
- spreadsheet.Add(new DataCell("", "", "", "", "", ""));
- spreadsheet.Add(new DataCell("", "", "", "", "", ""));
- spreadsheet.Add(new DataCell("", "", "", "", "", ""));
- spreadsheet.Add(new DataCell("", "", "", "", "", ""));
- spreadsheet.Add(new DataCell("", "", "", "", "", ""));
- spreadsheet.Add(new DataCell("", "", "", "", "", ""));
- dataGrid2.ItemsSource = spreadsheet;
- }
- private void dataGrid2_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
- {
- // I want to get the current cell value using the below
- // string myString = dataGrid1.CurrentItem.ToString();
- // the calculation seems to work with this when i pass it to textbox1 and set the myString Variable in the code.
- string myString = "10 * 10";
- string[] parts = myString.Split(' ');
- int part1 = int.Parse(parts[0]);
- // string part2 = parts[1];
- int part3 = int.Parse(parts[2]);
- int answer = part1 * part3;
- string answer2 = answer.ToString();
- // dataGrid2.CurrentItem = answer2;
- // seems to work when i pass to the below textbox instead of back to the cell above
- textBox1.Text = answer2;
- }
- }
- ((TextBox)e.EditingElement).Text
Add Comment
Please, Sign In to add comment