Hello,
I have tried the MultiRow Example and I love it!
Currently I have 8 columns, C1 - C8. My layout is
1) everything in one row
C1 C2 C3 C4 C5 C6 C7 C8
and
2) multirow
| C1 || C2 || C3 |
| C4 || C5 |
| C6 || C7 || C8 |
Now I am using the celltype Combobox for C1 as the user should select the value for this data by choosing from only several choices.
My code is
private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e)
{
GridDataBoundGrid grid = sender as GridDataBoundGrid;
if (e.ColIndex == 1 && e.RowIndex > 0)
{
StringCollection items = new StringCollection();
items.Add("One");
items.Add("Two");
items.Add("Three");
e.Style.CellType = "ComboBox";
e.Style.ChoiceList = items;
}
}
}
this works fine when everything is displayed in one row. But if I switch to multirow all of the three columns in the first column (C1, C4 and C6) will receive the combobox. This is wrong. I have tried to check the MappingName of the cells with
string strColumnName = this.gridDataBoundGrid1.Binder.InternalColumns[e.ColIndex].MappingName;
but this does not help
My current workaround checkeds if MultiRow is enabled and counts the row so that only every third row gets the combobox (e.RowIndex % 3 == 0). But I would prefer a solution which depends on the underlying fieldname or dataname or anything other unique and reliable property.
Any idea would be great! ;)
Thank you
Alex
AD
Administrator
Syncfusion Team
March 22, 2007 04:48 PM UTC
Hi Alex,
Here is a code snippet that shows you "How to get the mapping name of the required column in a GridDataBoundGrid if the colindex and its rowIndex is given?".
public string GetMappingName(GridDataBoundGrid grid,int RowIndex, int ColIndex )
{
GridBoundRecordState rs = grid.Binder.GetRecordStateAtRowIndex(RowIndex);
int MultiRecordRowCount = rs.RowIndexInRecord;
int iColCount = grid.Model.ColCount;
int index = ( rs.RowIndexInRecord * iColCount ) + ColIndex + rs.RowIndexInRecord;
GridBoundColumnsCollection columns = grid.Binder.GridBoundColumns;
if( columns != null && columns.Count > 0 )
{
GridBoundColumn column = grid.Binder.GridBoundColumns[ index - 1 ];
return column.MappingName;
}
else
return grid.Binder.InternalColumns[ grid.Binder.ColIndexToField(ColIndex)].MappingName;
}
Usage of the GetMappingName method in a QueryCellInfo event of the grid.
private void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if( e.RowIndex > 0 && e.ColIndex > 0 )
{
if( GetMappingName( gridDataBoundGrid1,e.RowIndex,e.ColIndex ) == "ColumnName" )
e.Style.BackColor = Color.Red;
}
}
Best regards,
Haneef
AD
Administrator
Syncfusion Team
March 22, 2007 05:41 PM UTC
Hi Alex,
Please ignore by previous post. You can use the GridHierarchyLevel.RowFieldToField method to calculates a zero-based field number that can be used as an index in the InternalColumns based on the zero-based row index in the record and the zero-based field column in the grid. Please try this code snippet and let me know if this helps.
public string GetMappingName(GridModelDataBinder binder,int RowIndex, int ColIndex)
{
GridBoundRecordState rs = binder.GetRecordStateAtRowIndex(RowIndex);
GridHierarchyLevel level = gridDataBoundGrid1.Binder.GetHierarchyLevel(rs.LevelIndex);
int field = binder.ColIndexToField(ColIndex);
int rowfield = level.RowFieldToField( rs.RowIndexInRecord, field );
return binder.InternalColumns[ rowfield ].MappingName;
}
Best regards,
Haneef
AD
Administrator
Syncfusion Team
March 23, 2007 10:24 AM UTC
Yes, it works wonderful!
Thank you very much!
Alex