This is a migrated thread and some comments may be shown as answers.

Unhandled Error in Silverlight Application code 4004 on deleting adding column at runtime

0 Answers 82 Views
GridView
This is a migrated thread and some comments may be shown as answers.
sumant
Top achievements
Rank 1
sumant asked on 03 Jun 2011, 01:26 PM
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?

No answers yet. Maybe you can help?

Tags
GridView
Asked by
sumant
Top achievements
Rank 1
Share this question
or