This example demonstrates how to use different data editors to display and edit cell values. The RichEditControl is used to edit RTF data (it is displayed within a popup window). The RepositoryItemRichTextEdit is used to display RTF data in data cells.
The CustomRowCellEditForEditing event is handled to assign a custom RTF editor to a column for in-place editing (to override the default column editor):
C#void gridView1_CustomRowCellEditForEditing(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e) {
if (e.Column.FieldName == "Rich")
e.RepositoryItem = riPopup;
}
Files to Review
- Form1.cs (VB: Form1.vb)
- RTFTestProvider.cs (VB: RTFTestProvider.vb)
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
C#// Developer Express Code Central Example:
// How to display rich text in GridView's cells, but edit their content in a popup window
//
// This example demonstrates how to provide different editors for displaying and
// editing data. In this scenario, cells values can be edited using the
// RichEditControl located in the popup window. However, the
// RepositoryItemRichTextEdit is used to display cells content when their in-place
// editor is closed.
//
// You can find sample updates and versions for different programming languages here:
// http://www.devexpress.com/example=E2503
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors;
using DevExpress.XtraRichEdit;
using DevExpress.XtraEditors.Controls;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private DataTable CreateTable(int RowCount)
{
DataTable tbl = new DataTable();
tbl.Columns.Add("Name", typeof(string));
tbl.Columns.Add("ID", typeof(int));
tbl.Columns.Add("Number", typeof(int));
tbl.Columns.Add("Date", typeof(DateTime));
tbl.Columns.Add("Rich", typeof(string));
for (int i = 0; i < RowCount; i++)
tbl.Rows.Add(new object[] { String.Format("Name{0}", i), i, 3 - i, DateTime.Now.AddDays(i), RTFTextProvider.GetRichText(i) });
return tbl;
}
public Form1()
{
InitializeComponent();
gridControl1.DataSource = CreateTable(20);
gridView1.OptionsView.RowAutoHeight = true;
gridView1.RowHeight = 30;
gridColumn1.Width = 20;
riPopup.PopupFormMinSize = new Size(400, 400);
}
void gridView1_CustomRowCellEditForEditing(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
{
if (e.Column.FieldName == "Rich")
e.RepositoryItem = riPopup;
}
void riPopup_QueryPopUp(object sender, CancelEventArgs e)
{
BaseEdit editor = (BaseEdit)sender;
richEditControl.Document.RtfText = editor.EditValue.ToString();
}
void riPopup_QueryDisplayText(object sender, QueryDisplayTextEventArgs e)
{
e.DisplayText = richEditControl.Document.Text;
}
void riPopup_QueryResultValue(object sender, QueryResultValueEventArgs e)
{
e.Value = richEditControl.Document.RtfText;
}
private void riPopup_CloseUp(object sender, CloseUpEventArgs e) {
if(!e.AcceptValue) {
PopupContainerEdit pSender = (PopupContainerEdit)sender;
RichEditControl rEdit = (RichEditControl)pSender.Properties.PopupControl.Controls[0];
rEdit.Document.RtfText = e.Value.ToString();
}
}
}
}
C#// Developer Express Code Central Example:
// How to display rich text in GridView's cells, but edit their content in a popup window
//
// This example demonstrates how to provide different editors for displaying and
// editing data. In this scenario, cells values can be edited using the
// RichEditControl located in the popup window. However, the
// RepositoryItemRichTextEdit is used to display cells content when their in-place
// editor is closed.
//
// You can find sample updates and versions for different programming languages here:
// http://www.devexpress.com/example=E2503
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsApplication1
{
public static class RTFTextProvider
{
private static string _TestText;
static RTFTextProvider()
{
StreamReader tr = new StreamReader("..\\..\\RTFText.rtf");
_TestText = tr.ReadToEnd();
}
public static object GetRichText(object obj)
{
return _TestText.Replace("TextToReplace", obj.ToString());
}
}
}