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.

Problem with Celltype ComboBox in MultiRow Example

Thread ID:

Created:

Updated:

Platform:

Replies:

58339 Mar 22,2007 07:15 AM Mar 23,2007 06:24 AM Windows Forms 3
loading
Tags: GridControl
Alex
Asked On March 22, 2007 07:15 AM

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



Administrator [Syncfusion]
Replied On March 22, 2007 12:48 PM

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

Administrator [Syncfusion]
Replied On March 22, 2007 01:41 PM

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

Administrator [Syncfusion]
Replied On March 23, 2007 06:24 AM

Yes, it works wonderful!

Thank you very much!

Alex

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.

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.

;