This question is locked. New answers and comments are not allowed.
Hi All,
I need urgent help for my project purpose. I am using a gridview. In which I am trying to insert some columns dynamically. As these columns depend on different parameters so while populating the grid different columns will be inserted. For that whenever I am populating the grid for second time first I am deleting the older dynamically added columns and adding the new one. But I am getting whever I am populating the grid for second time.
Below is the code I am using to dynamically ass and remove columns.
//delete old columns
foreach (string approvalUser in tempSchemaList)
{
if (((GridViewDataColumn)dgEng.Columns[approvalUser]) != null)
dgEng.Columns.Remove((GridViewDataColumn)dgEng.Columns[approvalUser])
}
//inserting new columns
foreach (string approvalUser in approverUsers)
{
GridViewDataColumn datacolumn = new GridViewDataColumn();
datacolumn.Header = approvalUser;
datacolumn.UniqueName = approvalUser;
datacolumn.SortingState = SortingState.Ascending; datacolumn.DataMemberBinding = new System.Windows.Data.Binding(“ab”);
Interaction.GetBehaviors(datacolumn).Add(new ClosePopupOnApplyFilterBehavior());
dgEng.Columns.Insert(insertIndex, datacolumn);
insertCount++;
insertIndex++;
}
}
/////////////////////////
And while populating the grid for second time I am getting the following error:
Line: 57
Error: Unhandled Error in Silverlight Application
Code: 4004
Category: ManagedRuntimeError
Message: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at System.Windows.ResourceManagerWrapper.GetResourceForUri(Uri xamlUri, Type componentType)
///////////
Please suggest what is wrong and what to do?
I need urgent help for my project purpose. I am using a gridview. In which I am trying to insert some columns dynamically. As these columns depend on different parameters so while populating the grid different columns will be inserted. For that whenever I am populating the grid for second time first I am deleting the older dynamically added columns and adding the new one. But I am getting whever I am populating the grid for second time.
Below is the code I am using to dynamically ass and remove columns.
//delete old columns
foreach (string approvalUser in tempSchemaList)
{
if (((GridViewDataColumn)dgEng.Columns[approvalUser]) != null)
dgEng.Columns.Remove((GridViewDataColumn)dgEng.Columns[approvalUser])
}
//inserting new columns
foreach (string approvalUser in approverUsers)
{
GridViewDataColumn datacolumn = new GridViewDataColumn();
datacolumn.Header = approvalUser;
datacolumn.UniqueName = approvalUser;
datacolumn.SortingState = SortingState.Ascending; datacolumn.DataMemberBinding = new System.Windows.Data.Binding(“ab”);
Interaction.GetBehaviors(datacolumn).Add(new ClosePopupOnApplyFilterBehavior());
dgEng.Columns.Insert(insertIndex, datacolumn);
insertCount++;
insertIndex++;
}
}
/////////////////////////
And while populating the grid for second time I am getting the following error:
Line: 57
Error: Unhandled Error in Silverlight Application
Code: 4004
Category: ManagedRuntimeError
Message: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at System.Windows.ResourceManagerWrapper.GetResourceForUri(Uri xamlUri, Type componentType)
///////////
Please suggest what is wrong and what to do?