Hi
I am doing some calculation on a column. i.e calculating % for 2 other columns.
I have done this in querycellstyleinfo event but i am getting calculations done for alternate records only. I checked and found that event is fired for alternate rows only i,e if i have 6 records then event is fired only for 3 times
Please can you help me solving this.
This is very urgent
Please help
Thanks
Harshad
AD
Administrator
Syncfusion Team
March 19, 2007 06:55 PM UTC
Hi Harshad,
There is no built-in event for detecting alternate rows in a DataBoundGrid. If you want to detect the alternate rows in a grid, you would have to derive the GridDataBound control and override the OnPrepareViewStyleInfo method to fire the event . Please try the below code and let me know if this helps.
public class MyGridDataBoundGrid : GridDataBoundGrid
{
public delegate void AlternatePrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e);
public event AlternatePrepareViewStyleInfo AlternateRowPrepareViewStyle;
public MyGridDataBoundGrid(){}
protected override void OnPrepareViewStyleInfo(GridPrepareViewStyleInfoEventArgs e)
{
if( AlternateRowPrepareViewStyle != null)
{
if( e.RowIndex % 2 == 0 )
AlternateRowPrepareViewStyle(this,e);
}
base.OnPrepareViewStyleInfo (e);
}
}
//Create instance of the MyGridDataBoundGrid and subscribe the AlternateRowPrepareViewStyleInfo event.
this.gridDataBoundGrid1 = new MyGridDataBoundGrid();
this.gridDataBoundGrid1.AlternateRowPrepareViewStyle +=new AlternatePrepareViewStyleInfo(gridDataBoundGrid1_AlternateRowPrepareViewStyle);
private void gridDataBoundGrid1_AlternateRowPrepareViewStyle(object sender, GridPrepareViewStyleInfoEventArgs e)
{ e.Style.BackColor = Color.Red; }
Best regards,
Haneef
AD
Administrator
Syncfusion Team
March 20, 2007 08:36 AM UTC
I dont want alternate rows....Actually i am facing that problem only.....i want to do the % calculation for each row. I have wriiten code in QueryCellStyleInfo event. But it is calculating for alternate rows only and not for each row.
I am not able to find out the cause of this.
Please tellme where i am doing wrong.
Thanks
Harshad
AD
Administrator
Syncfusion Team
March 20, 2007 09:32 PM UTC
Hi Harshad,
Please try to provide us some more information on this issue. I tried to reproduce the issue, but couldn't. kindly provide us a small sample to reproduce the issue or modify the browser sample accordingly. This will help us to analyse the issue further.
Best Regards,
Haneef
AD
Administrator
Syncfusion Team
March 21, 2007 10:58 AM UTC
Hi,
I got the cause of this problem.
I was checking condition like
e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell
i dont know why but when i put this condition i get the calculations and formating for alternate rows only and not all rows. Why it consider alternate rows as recordfieldcell and not all rows cell..?
AD
Administrator
Syncfusion Team
March 21, 2007 02:28 PM UTC
Hi Harshad,
The reason is that you are checking the RecordFileldCell only. Also you need to check the AlternateRecordFileldCell in a QueryCellStyleInfo event. Please find the code snippet below.
if ( e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell || e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell )
{
//code here...
}
Best regards,
Haneef