使第三列不可见并检索值 [英] Make the third Column invisibly and Retrieve value

查看:75
本文介绍了使第三列不可见并检索值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:

显示两列而不显示richtextbox内的第三列







第三列不得占用richtextbox中的任何空格。你应该只看到两列,实际上它是richtextbox里面的三列。





问题:

当我想从表中检索值时,我也应该从第三列检索值。

主要问题是怎么做?

我试过但却失败了。我不知道需要什么语法代码。



Goal:
Display two column without displaying the third column inside of richtextbox

and

the third column shall not take any space in the richtextbox. You should only see two column and in reality it is three column inside of richtextbox.


Problem:
When I want to retrieve the value from the table, I also should retrieve value from third column.
The main problem is how to do it?
I have tried it but failed. I do not know what syntax code is needed.

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);
                }
            }
        }

推荐答案

这篇关于使第三列不可见并检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆