Razack
Razack

Reputation: 1896

show Rich text Formatted data in an infragistics win grid cell

How do I show Rich text Formatted Text in an Ultra Win Grid cell (infragistics). I am storing this data as a varbinary(MAX) in the database.

Upvotes: 0

Views: 3333

Answers (1)

Dmitriy Konovalov
Dmitriy Konovalov

Reputation: 1817

With Infragistics you have a lot of options how to implement this feature. Let me show you the easiest way:

  1. Set column properties after you set Grid.DataSource property:
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. Allow users to open links in rtf text:
private void rtfColumnn_LinkClicked(object sender, Infragistics.Win.FormattedLinkLabel.LinkClickedEventArgs e)
{
    e.OpenLink = true;
}
  1. Subscribe for event BeforeEnterEditMode:
bindingGrid.BeforeEnterEditMode += this.Grid_BeforeEnterEditMode;
  1. And show a nice infragistics rtf editor instead of incell editing:
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;
        }
}

Upvotes: 1

Related Questions