Hi together,
I have a GGC with three columns ("A", "B", "C"). Now for several rows I need different cell types for column "C".
I thought I create a custom cell model and a custom cell renderer for column "C". In that column I thought I can use a factory to create the corresponding cell (custom form etc.). So when I click on a cell in a row for the column "C" I want to decide if I show a combobox button or just using a simple text box.
I used the OnInitialize(int rowIndex, int colIndex) method of the cell renderer to solve this. But this doesn't really work, because the OnInitialize method seems to be called for all cell in the column. So what is the best way to have different cell types in a GGC?
Any help would be great,
Cheers,
Chris
AD
Administrator
Syncfusion Team
November 28, 2006 11:49 AM UTC
Hi Chris,
To set cell specific properties in a GroupingGrid, you must catch the QueryCellStyleInfo event (or TableControlPrepareViewStyleInfo). In your handler, you check e.TableCellIdentity.ColIndex & e.TableCellIdentity.RowIndex and set the e.Style.CellType to the value you want. Here is a code snippet to show this.
private void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if( e.TableCellIdentity.RowIndex > 0
&& e.TableCellIdentity.ColIndex ==2 )
{
if( e.TableCellIdentity.RowIndex % 2 == 0 )
e.Style.CellType = "ComboBox";
else
e.Style.CellType = "PushButton";
}
}
Best Regards,
Haneef
AD
Administrator
Syncfusion Team
November 28, 2006 01:37 PM UTC
Hi,
thanks, this is what I was looking for. However, how can I get the underlying data in the QueryCellStyleInfo event. When I try to call gridGroupingControl.TableModel[e.TableCellIdentity.RowIndex,e.TableCellIdentity.ColIndex]
I get a stack overflow.
As background information I want to know about the underlying data of the current row and the current column to set the corresponding cell type. The data (especially the data type varies for every row).
Cheers,
Chris
AD
Administrator
Syncfusion Team
November 29, 2006 05:41 AM UTC
Hi Chris,
You can use ParentTable.CurrentRecord property to get the current record details in a grid. Andalso get the Current Column name using the e.TableCellIdentity.Column property. Here is a code snippet to show this.
private void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
{
Element eDisplayElement = e.TableCellIdentity.DisplayElement;
if( eDisplayElement.Kind == DisplayElementKind.Record
&& eDisplayElement.ParentTable != null )
{
GridGroupingControl grid = sender as GridGroupingControl;
GridTableControl tc = grid.GetTableControl(eDisplayElement.ParentTableDescriptor.Name);
int iCurrentRowIndex = tc.CurrentCell.RowIndex;
int iCurrentColIndex = tc.CurrentCell.RowIndex;
if( iCurrentRowIndex == e.TableCellIdentity.RowIndex && iCurrentColIndex != e.TableCellIdentity.ColIndex )
{
Record rCurrentRecord = eDisplayElement.ParentTable.CurrentRecord;
if( rCurrentRecord != null )
{
DataRowView row1 = rCurrentRecord.GetData() as DataRowView;
GridColumnDescriptor columns = e.TableCellIdentity.Column;
if( columns != null)
{
//you can set the celltype here.........
Console.WriteLine( "CurrentColumn " +columns.Name + "Record => " + rCurrentRecord );
}
}
}
}
}
Best Regards,
Haneef
AD
Administrator
Syncfusion Team
November 29, 2006 09:33 AM UTC
Hi Haneef,
thanks for your fast answer, your code works fine. I have one question about the follwing line:
if( iCurrentRowIndex == e.TableCellIdentity.RowIndex && iCurrentColIndex != e.TableCellIdentity.ColIndex )
especially the part:
iCurrentColIndex != e.TableCellIdentity.ColIndex
Why do you use the != operator here instead of == do the two index parameter start with a different value (0 vs 1)?
Cheers
AD
Administrator
Syncfusion Team
November 29, 2006 09:57 AM UTC
Hi Chris,
Sorry for the inconvenience caused. I have mistakenly put the != operator instead of == operator. Could you please try this code
if( iCurrentRowIndex == e.TableCellIdentity.RowIndex && iCurrentColIndex == e.TableCellIdentity.ColIndex )
{
//code
}
Thanks for using the Syncfusion Products.
Best Regards,
Haneef
AD
Administrator
Syncfusion Team
November 29, 2006 10:23 AM UTC
Hi Haneef,
I switched the operator now my interesting code gets never called (setting a different cell type). This is because of the following:
if (iCurrentRowIndex == e.TableCellIdentity.RowIndex &&
iCurrentColIndex == e.TableCellIdentity.ColIndex)
it seems that the parameter "iCurrentRowIndex" and "iCurrentColIndex" start with a different value as "e.TableCellIdentity.RowIndex" and "e.TableCellIdentity.ColIndex". Could it be possible that one counts the row and column headers and the other doesn't?
void QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
Element eDisplayElement = e.TableCellIdentity.DisplayElement;
if (eDisplayElement.Kind == DisplayElementKind.Record &&
eDisplayElement.ParentTable != null)
{
GridGroupingControl grid = sender as GridGroupingControl;
GridTableControl tc = grid.GetTableControl(eDisplayElement.ParentTableDescriptor.Name);
int iCurrentRowIndex = tc.CurrentCell.RowIndex;
int iCurrentColIndex = tc.CurrentCell.RowIndex;
if (iCurrentRowIndex == e.TableCellIdentity.RowIndex &&
iCurrentColIndex == e.TableCellIdentity.ColIndex)
{
Record rCurrentRecord = eDisplayElement.ParentTable.CurrentRecord;
if (rCurrentRecord != null)
{
DetectionSetting currSetting = rCurrentRecord.GetData() as DetectionSetting;
GridColumnDescriptor column = e.TableCellIdentity.Column;
if (column != null && column.MappingName == "ExampleColumn")
{
if (currSetting.ParameterValue.GetType() == typeof(Test))
{
e.Style.CellType = "MyCellType";
}
//you can set the celltype here.........
//Console.WriteLine("CurrentColumn: " + columns.Name + " Record => " + rCurrentRecord);
}
}
}
}
}
AD
Administrator
Syncfusion Team
November 29, 2006 10:30 AM UTC
small addon to my previous posting, the following line solves the problem:
if (iCurrentRowIndex == e.TableCellIdentity.RowIndex &&
iCurrentColIndex == e.TableCellIdentity.ColIndex + 1 )
So it seems that the column indizies count different - any ideas?
Cheers
AD
Administrator
Syncfusion Team
November 29, 2006 10:43 AM UTC
Hi Chris,
Could you please try this code snippet
private void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
{
Element eDisplayElement = e.TableCellIdentity.DisplayElement;
if( eDisplayElement.Kind == DisplayElementKind.Record
&& eDisplayElement.ParentTable != null )
{
GridGroupingControl grid = sender as GridGroupingControl;
GridTableControl tc = grid.GetTableControl(eDisplayElement.ParentTableDescriptor.Name);
int iCurrentRowIndex = tc.CurrentCell.RowIndex;
///****************Begin Modification***************************************
//// int iCurrentColIndex = tc.CurrentCell.RowIndex;//you need to get the colIndex of the CurrentCell here.
int iCurrentColIndex = tc.CurrentCell.ColIndex;
///you can use the == instead of using the != operator.
if( iCurrentRowIndex == e.TableCellIdentity.RowIndex && iCurrentColIndex == e.TableCellIdentity.ColIndex )
{
///***************EndModification*********************************************
Record rCurrentRecord = eDisplayElement.ParentTable.CurrentRecord;
if( rCurrentRecord != null )
{
DataRowView row1 = rCurrentRecord.GetData() as DataRowView;
GridColumnDescriptor columns = e.TableCellIdentity.Column;
if( columns != null)
{
//you can set the celltype here.........
Console.WriteLine( "CurrentColumn " +columns.Name + "Record => " + rCurrentRecord );
}
}
}
}
}
Let me know if this helps.
Best Regards,
Haneef