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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Formatted Text

Thread ID:

Created:

Updated:

Platform:

Replies:

64184 Jul 16,2007 04:35 PM UTC Jul 19,2007 10:37 PM UTC Windows Forms 8
loading
Tags: GridControl
Thanvir Hussain
Asked On July 16, 2007 04:35 PM UTC

Hi,
I have created a custom cell which when I input 1m interprets and shows as 1,000,000.00. I have overridden OnPrepareViewStyleInfo.

Now if I want to refer the cell value to another cell by putting a formula as =A2, I get the value as 1m instead of 1,000,000.00 and my formula fails. How do I do this?

thanks
thanvir

haneefm [Syncfusion]
Replied On July 16, 2007 11:09 PM UTC

Hi Thanvir,

The reason for getting this behavior is that you are using the OnPrepareViewStyleinfo method to set the cellvalue in a grid cell. The OnPrepareviewStyleInfo method does not store any styleInfo properties in a grid. It just set the visual apperence of the grid. If you want to store the cellvalue then go to QueryCellInfo event.

In you cusom cell renderer ctor(), you can subscribe the QueryCellInfo event of the GridModel and set e.Style.CellValue to 1,00,000 when the '1m' is pressed. Below is a code snippet.

this.grid.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(HandleQueryCellInfo);

//the handler
private void HandleQueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if(e.Style.CellModel.GetType() == typeof(YourCustomCellModel) )
e.Style.CellValue = 1,00,000;
}

Best regards,
Haneef

Thanvir Hussain
Replied On July 17, 2007 10:53 AM UTC

Hi,
The e.Style.CellModel.GetType() always gives back GridTextBoxCellModel, even though I have given the grid cell type as my custom cell model. So this condition is never true.

Regards
thanvir

>Hi Thanvir,

The reason for getting this behavior is that you are using the OnPrepareViewStyleinfo method to set the cellvalue in a grid cell. The OnPrepareviewStyleInfo method does not store any styleInfo properties in a grid. It just set the visual apperence of the grid. If you want to store the cellvalue then go to QueryCellInfo event.

In you cusom cell renderer ctor(), you can subscribe the QueryCellInfo event of the GridModel and set e.Style.CellValue to 1,00,000 when the '1m' is pressed. Below is a code snippet.

this.grid.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(HandleQueryCellInfo);

//the handler
private void HandleQueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if(e.Style.CellModel.GetType() == typeof(YourCustomCellModel) )
e.Style.CellValue = 1,00,000;
}

Best regards,
Haneef

Thanvir Hussain
Replied On July 17, 2007 11:03 AM UTC

Hi,
In the OnPrepareViewStyleInfo method I could see that the e.Style refers to my custom cellmodel but in the QueryCellInfo method it is always GridTextBoxCellModel.

Regards
thanvir

>Hi,
The e.Style.CellModel.GetType() always gives back GridTextBoxCellModel, even though I have given the grid cell type as my custom cell model. So this condition is never true.

Regards
thanvir

>Hi Thanvir,

The reason for getting this behavior is that you are using the OnPrepareViewStyleinfo method to set the cellvalue in a grid cell. The OnPrepareviewStyleInfo method does not store any styleInfo properties in a grid. It just set the visual apperence of the grid. If you want to store the cellvalue then go to QueryCellInfo event.

In you cusom cell renderer ctor(), you can subscribe the QueryCellInfo event of the GridModel and set e.Style.CellValue to 1,00,000 when the '1m' is pressed. Below is a code snippet.

this.grid.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(HandleQueryCellInfo);

//the handler
private void HandleQueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if(e.Style.CellModel.GetType() == typeof(YourCustomCellModel) )
e.Style.CellValue = 1,00,000;
}

Best regards,
Haneef

haneefm [Syncfusion]
Replied On July 17, 2007 06:51 PM UTC

Hi Thanvir,

Are you setting the celltype of the grid cell to your custom cell type in a PrepareViewStyle event?. If yes, you can set the celltype of the cell in QueryCellInfo event. The PrepareViewStyleinfo method does not store any styleInfo properties(CellType,CellModel,etc) in a grid. It just set the visual apperence of the grid .Here is a minimal sample that shows you "How to get the cellmodel type from Model.QueryCellInfo event in custom cell renderer of the grid?"

DerivedCellModel.zip

[c#]
if( typeof(MyComboBoxCellModel)== e.Style.CellModel.GetType() )
{
e.Style.BackColor = Color.Red;
}

Best regards,
Haneef

Thanvir Hussain
Replied On July 18, 2007 09:08 AM UTC

Hi,
I am not setting the style for the entire column but only for a particular cell. In your example if I change the following
//this.gridControl1.ColStyles[1].ChoiceList = sc;
//GridStyleInfo style = this.gridControl1.ColStyles[1];

GridStyleInfo style = this.gridControl1[2, 2];

style.CellType = "MyComboBox";
style.ChoiceList = sc;

It does not work.

Does it mean that I will only work if set the style for the entire column?

Regards
thanvir

>Hi Thanvir,

Are you setting the celltype of the grid cell to your custom cell type in a PrepareViewStyle event?. If yes, you can set the celltype of the cell in QueryCellInfo event. The PrepareViewStyleinfo method does not store any styleInfo properties(CellType,CellModel,etc) in a grid. It just set the visual apperence of the grid .Here is a minimal sample that shows you "How to get the cellmodel type from Model.QueryCellInfo event in custom cell renderer of the grid?"

DerivedCellModel.zip

[c#]
if( typeof(MyComboBoxCellModel)== e.Style.CellModel.GetType() )
{
e.Style.BackColor = Color.Red;
}

Best regards,
Haneef

Rajagopal [Syncfusion]
Replied On July 19, 2007 01:34 AM UTC

Hi Thanvir,

There are some precedences among styles that are set for different GridStyleInfo objects. The styles that are set in the ColumnStyles are less precedent over cellstyles. The QueryCellInfo gets fired anytime the grid needs a cell style for any reason. The PrepareViewStyleInfo is fired after the QueryCellInfo. This event can be handled to modify style properties immediately before the style is used to draw the cell.

To resolve this issue, ignore the Model_QueryCellInfo and add the code below in the OnPrepareViewStyleInfo override of the derived GridComboBoxCellRenderer.

public override void OnPrepareViewStyleInfo(GridPrepareViewStyleInfoEventArgs e)
{
if(e.Style.CellModel.GetType()== typeof(MyComboBoxCellModel))
{
e.Style.BackColor = Color.Red;
}
base.OnPrepareViewStyleInfo (e);
}

Take a look at this sample for more information on the styles precedences in grid.
\\Syncfusion\EssentialStudio\5.1\Windows\Grid.Windows\Samples\2.0\Appearance\GridStyleInfoAtWork

Have a nice time.
Regards,
Rajagopal

Thanvir Hussain
Replied On July 19, 2007 08:51 AM UTC

HI,
I want to change the cellvalue which can't be done in the PrepareViewStyleInfo method, please suggest any other alternative. Also, I have detailed in the starting of the discussion thread what I am looking for?
Regards
thanvir

>Hi Thanvir,

There are some precedences among styles that are set for different GridStyleInfo objects. The styles that are set in the ColumnStyles are less precedent over cellstyles. The QueryCellInfo gets fired anytime the grid needs a cell style for any reason. The PrepareViewStyleInfo is fired after the QueryCellInfo. This event can be handled to modify style properties immediately before the style is used to draw the cell.

To resolve this issue, ignore the Model_QueryCellInfo and add the code below in the OnPrepareViewStyleInfo override of the derived GridComboBoxCellRenderer.

public override void OnPrepareViewStyleInfo(GridPrepareViewStyleInfoEventArgs e)
{
if(e.Style.CellModel.GetType()== typeof(MyComboBoxCellModel))
{
e.Style.BackColor = Color.Red;
}
base.OnPrepareViewStyleInfo (e);
}

Take a look at this sample for more information on the styles precedences in grid.
\\Syncfusion\EssentialStudio\5.1\Windows\Grid.Windows\Samples\2.0\Appearance\GridStyleInfoAtWork

Have a nice time.
Regards,
Rajagopal

haneefm [Syncfusion]
Replied On July 19, 2007 10:37 PM UTC

Hi Thanvir,

One way you can do this by hanlding the OnDraw method of the grid and set the value of the cell using the Model indexer. Below is a code snippet.

protected override void OnDraw(Graphics g, Rectangle clientRectangle, int rowIndex, int colIndex, GridStyleInfo style)
{
string sText = this.Grid.Model[rowIndex, colIndex].Text;
if (sText != string.Empty && sText.EndsWith("m") )
{
System.Int32 iText = Convert.ToInt32( sText.Substring(0, sText.Length - 1)) * 1000000;
this.Grid.Model[rowIndex, colIndex].CellValue = iText;
}
base.OnDraw(g, clientRectangle, rowIndex, colIndex, style);
}

Please try the sample for implementation and let me know if this helps.
ModifiedDerivedCellModel.zip

Best regards,
Haneef

CONFIRMATION

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.

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

;