We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Custom Cell Model - Change CellValue Issue!

Thread ID:





8098 Oct 21,2003 12:45 AM UTC Oct 21,2003 08:07 AM UTC WinForms 2
Tags: GridControl
Asked On October 21, 2003 12:45 AM UTC

Hi guys! I'm trying to create a custom cell model which alters the displayed value (cell value) of bound data for specific cells. My solution seems to work except when 'on' the current cell. Are you only supposed to change cell values for this purpose in the grid event QueryCellInfo or is my way valid and just not working properly? The reason why I want this is to define special custom grid column types which can show 'Hello Wo...' for truncated text in addition to other more application specific needs. I have attached a sample app which shows the problem. Thanks in advance, Marcus.

Administrator [Syncfusion]
Replied On October 21, 2003 08:01 AM UTC

You could do this in a PrepareViewStyleInfo event handler without deriving a cell control. But deriving a cell control will probably be more efficient as PrepareViewStyleInfo is hit a lot. In your OnDraw override, do not call the baseclass to do the drawing. In the base class, the value stored in the original style is drawn and you do not want this. Instead, call the static GridStaticCellRenderer.DrawText method to draw the text. Doing so, allows you to specify the exact text to be drawn.
protected override void OnDraw(System.Drawing.Graphics g, System.Drawing.Rectangle clientRectangle, 
			int rowIndex, int colIndex, GridStyleInfo style)
	int i = (int)style.CellValue * 10;
	//style.CellValueType = typeof(string);
	//style.CellValue = "Val = " + i.ToString();
	string text = "Val = " + i.ToString();
	//base.OnDraw(g, clientRectangle, rowIndex, colIndex, style);
	GridStaticCellRenderer.DrawText(g, text, style.GdipFont, clientRectangle, style, style.TextColor);

Administrator [Syncfusion]
Replied On October 21, 2003 08:07 AM UTC

Try overriding the GridCellModelBase.GetFormattedText method or handle the GridModel.QueryFormattedText event. Then there is no need to change the .CellValue in OnDraw. If you then still want to change the contents of the current cell try handling the CurrentCellInitializeControlText event. Stefan


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon