private void Window_Loaded(object sender, RoutedEventArgs e) { var tab = new Table(); tab.Name = "MyTable"; newRtb.RegisterName("MyTable", tab); var gridLenghtConvertor = new GridLengthConverter(); tab.Columns.Add(new TableColumn() { Name = "Column1", Width = (GridLength)gridLenghtConvertor.ConvertFromString("*") }); tab.Columns.Add(new TableColumn() { Name = "Column2", Width = (GridLength)gridLenghtConvertor.ConvertFromString("*") }); tab.RowGroups.Add(new TableRowGroup()); for (int i = 0; i < 10; i++) { TableRow tr = new TableRow(); tr.MouseLeftButtonDown += tr_MouseLeftButtonDown; tab.RowGroups[0].Rows.Add(tr); var tabRow = tab.RowGroups[0].Rows[i]; tabRow.Cells.Add(new TableCell(new Paragraph(new Run("Row" + (i + 1).ToString() + " Column1"))) { TextAlignment = TextAlignment.Center }); tabRow.Cells.Add(new TableCell(new Paragraph(new Run("Row" + (i + 1).ToString() + " Column2")))); } newRtb.Document.Blocks.Add(tab); } private void tr_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { //reset background of all rows: Table table = newRtb.FindName("MyTable") as Table; foreach (TableRow row in table.RowGroups[0].Rows) { row.Background = Brushes.Transparent; } //set background of selected row: TableRow tr = sender as TableRow; tr.Background = Brushes.SpringGreen; //get value of second cell: Paragraph p = tr.Cells[1].Blocks.FirstBlock as Paragraph; Run run = p.Inlines.FirstInline as Run; string text = run.Text; }
private void btn_test_Click(object sender, RoutedEventArgs e) { Table table = newRtb.FindName("MyTable") as Table; foreach (TableRow row in table.RowGroups[0].Rows) { if (row.Background == Brushes.SpringGreen) { //get value of second cell: Paragraph p = row.Cells[1].Blocks.FirstBlock as Paragraph; Run run = p.Inlines.FirstInline as Run; MessageBox.Show("Second cell value: " + run.Text); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)