在Infragistics win网格单元格中显示Rich text格式化数据

时间:2011-11-10 13:13:04

标签: ultrawingrid

如何在Ultra Win Grid单元格中显示富文本格式化文本(infragistics)。我将这些数据作为varbinary(MAX)存储在数据库中。

1 个答案:

答案 0 :(得分:1)

使用Infragistics,您有很多选择如何实现此功能。 让我告诉你最简单的方法:

  1. 设置 Grid.DataSource 属性后设置列属性:
  2. UltraGridColumn c = null;
    /// initialize c here. Lets suppose that it has a "rtf" key.
    c.Style = ColumnStyle.FormattedTextEditor;
    ((FormattedLinkEditor) c.Editor).UnderlineLinks = UnderlineLink.Always;
    ((FormattedLinkEditor)c.Editor).LinkClicked += new Infragistics.Win.FormattedLinkLabel.LinkClickedEventHandler(rtfColumnn_LinkClicked);
    c.MaskClipMode = MaskMode.Raw;
    ((FormattedLinkEditor) c.Editor).TreatValueAs = TreatValueAs.FormattedText;
    
    1. 允许用户以rtf文本打开链接:
    2. private void rtfColumnn_LinkClicked(object sender, Infragistics.Win.FormattedLinkLabel.LinkClickedEventArgs e)
      {
          e.OpenLink = true;
      }
      
      1. 订阅活动 BeforeEnterEditMode
      2. bindingGrid.BeforeEnterEditMode += this.Grid_BeforeEnterEditMode;
        
        1. 并显示一个很好的infragistics rtf编辑器而不是incell编辑:
        2. private void Grid_BeforeEnterEditMode(object sender, System.ComponentModel.CancelEventArgs e)
          {
              if (Grid.ActiveCell.Column.Key=="rtf")
                  {
                      Infragistics.Win.SupportDialogs.FormattedTextEditor.FormattedTextUIEditorForm rtf_frm =
                          new FormattedTextUIEditorForm();
                      rtf_frm.Value = Grid.ActiveCell.Value;
                      DialogResult dresult = rtf_frm.ShowDialog();
                      if (dresult == DialogResult.OK)
                      {
                          Grid.ActiveCell.Value = rtf_frm.Value;
                      }
          
                      e.Cancel = true;
                      return;
                  }
          }