Hi..
This error happens when we have a conditional formatting code and then you try to load a new layout. The error is "Exception thrown by the target of invocation". The workaround is to use the initialize grid row event instead of conditional formatting. Any ideas?
InitializeLayout event code: (Red color for numbers less than 0)
Infragistics.Win.Appearance appearanceRed = new Infragistics.Win.Appearance();
valAppearanceLessThen0.Add(conditionLessThen0, appearanceRed);
column.ValueBasedAppearance = valAppearanceLessThen0;
Load layout code on click of a button:
grdPnLGrid.DisplayLayout.LoadFromXml(LayoutFilenameTrades);
I'm having the exact same issue here using v8.1 of the WinGrid. Basically, display layouts cannot be loaded to the grid when I use conditional formatting on the columns. I get the "Exception has been thrown by the target of an invocation." exception.
Sample code (with oColumn being a column in the grid and ultraGrid1 being my grid):
ConditionValueAppearanceForm conditionValueAppearanceForm = new ConditionValueAppearanceForm( oColumn );DialogResult result = conditionValueAppearanceForm.ShowDialog( this );if ( result == DialogResult.OK ){ // If the user clicked OK, set the ConditionValueAppearance on the column. oColumn.ValueBasedAppearance = conditionValueAppearanceForm.ConditionValueAppearance; ultraGrid1.DisplayLayout.SaveAsXml( "layout.xml" ); ultraGrid1.DisplayLayout.LoadFromXml( "layout.xml" ); // This throws the exception}
If anyone has any ideas here, it would be greatly appreciated. I created an incident report already. I'm expecting my users to create their own simple or complex profiles, so I need the intended behavior. I have it so that a user could filter Column A and then set up formatting so that when Column B has a value greater than 0, Column A would show up with a background color of red. I can save that layout fine. But, I need the grid to have that view the next time he/she opens the application, and that's where the exception occurs every time. The exception goes away if I remove the conditional formatting from the column.
If you find a solution to this, please post it here.
The workaround (which is not performance efficient) that I am using is in the Initializerow event, I am checking the cell value and providing different appearance.