Git Product home page Git Product logo

how-to-display-rich-text-in-winforms-datagrid-sfdatagrid-'s Introduction

How to display rich text in WinForms DataGrid (SfDataGrid)?

This example explains how to display rich text in WinForms DataGrid (SfDataGrid).

WinForms DataGrid (SfDataGrid) doesn't have direct support to display RichText’s in the GridTextColumn. However, it is possible to achieve this by overriding the OnRender method in GridTextBoxCellRenderer.

//customize the TextBoxCellRenderer
this.sfDataGrid1.CellRenderers.Remove("TextBox");
this.sfDataGrid1.CellRenderers.Add("TextBox", new GridRichTextCellRenderer());

public class GridRichTextCellRenderer : GridTextBoxCellRenderer
{
    protected override void OnRender(Graphics paint, Rectangle cellRect, string cellValue, CellStyleInfo style, DataColumnBase column, RowColumnIndex rowColumnIndex)
    {
        //here customize based on your scenario
        if (column.GridColumn.MappingName == "CustomerID")
        {   //here draw the richtex in SfDataGrid             
            TextPainter.DrawRichText(paint, cellValue, cellRect);                
        }
        else
            base.OnRender(paint, cellRect, cellValue, style, column, rowColumnIndex);
    }
}   
'customize the TextBoxCellRenderer 
Me.sfDataGrid1.CellRenderers.Remove("TextBox")
Me.sfDataGrid1.CellRenderers.Add("TextBox", New GridRichTextCellRenderer())

Public Class GridRichTextCellRenderer
	Inherits GridTextBoxCellRenderer

	Protected Overrides Sub OnRender(ByVal paint As Graphics, ByVal cellRect As Rectangle, ByVal cellValue As String, ByVal style As CellStyleInfo, ByVal column As DataColumnBase, ByVal rowColumnIndex As RowColumnIndex)
		'here customize based on your scenario
		If column.GridColumn.MappingName = "CustomerID" Then 'here draw the richtex in SfDataGrid
			TextPainter.DrawRichText(paint, cellValue, cellRect)
		Else
			MyBase.OnRender(paint, cellRect, cellValue, style, column, row-ColumnIndex)
		End If
	End Sub
End Class

RichText_Image

You can download the example from GitHub

Requirements to run the demo

Visual Studio 2015 and above versions

how-to-display-rich-text-in-winforms-datagrid-sfdatagrid-'s People

Contributors

amalrajumapathyselvam avatar dhanasekarmohanraj avatar sarubala20 avatar syncfusionbuild avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.