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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Error after update sfDataGrid

Thread ID:





149503 Nov 28,2019 05:53 AM UTC Dec 2,2019 12:55 PM UTC WinForms 3
Tags: SfDataGrid
Asked On November 28, 2019 05:53 AM UTC

I have a problem with the update of the sfDataGrid Control.
I fill the sfDataGrid with a DataSet Table which comes from a SQLiteDataAdapter and has a relation to two SQLite tables.

as an example:

public static DataTable LoadAnfordungsDetails()
            DataSet ds = new DataSet();
            using (SQLiteConnection con = new SQLiteConnection(SQLDataConnection.LoadConnectionString()))
                SQLiteDataAdapter mitarbeiter = new SQLiteDataAdapter("SELECT * FROM tblMitarbeiter;", con);
                mitarbeiter.Fill(ds, "Mitarbeiter");
            using (SQLiteConnection cnn = new SQLiteConnection(SQLDataConnection.LoadConnectionString()))
                SQLiteDataAdapter details = new SQLiteDataAdapter("SELECT tblMitarbeiter.ID AS ID, tblAnforderungen.Name,tblAnforderungen.Klasse,tblAnforderungen.Beschreibung FROM tblKonfigDetails LEFT JOIN tblAnforderungen ON tblAnforderungen.ID = tblKonfigDetails.AnforderungID LEFT JOIN tblMitarbeiter ON tblMitarbeiter.ID = tblKonfigDetails.MitarbeiterID;", cnn);
                details.Fill(ds, "Details");
            ds.Relations.Add(new DataRelation("KonfigDetails", ds.Tables[0].Columns["ID"], ds.Tables[1].Columns["ID"]));
            if(ds.Tables.Count > 0)
                return ds.Tables[0];
                return null;

I fill the sfDataGrid in the constructor of the form. It all works great too.
But when did changed data I try to make an update to the sfDataGrid with:

                sfDataGrid1.DataSource = null;

This works so far, but as soon as I switch to the sfDataGrid I get in Program.cs -> Application.Run (new FrmMain ()); an exception.
System.ArgumentException: "An item with the same key has already been added."

System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unbehandelte Ausnahme</Description><AppDomain>USG Support Agent.exe</AppDomain><Exception><ExceptionType>System.ArgumentException, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Ein Element mit dem gleichen Schlüssel wurde bereits hinzugefügt.</Message><StackTrace>   bei System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   bei System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   bei Syncfusion.WinForms.DataGrid.DetailsViewHelper.HasChildSource(TableControl tableControl, Int32 rowIndex, RecordEntry record, Dictionary`2&amp;amp; detailsViewDataSource)
   bei Syncfusion.WinForms.DataGrid.Renderers.DetailsViewExpanderCellRenderer.OnRender(Graphics paint, Rectangle cellRect, String cellValue, CellStyleInfo style, DataColumnBase column, RowColumnIndex rowColumnIndex)
   bei Syncfusion.WinForms.DataGrid.Renderers.GridCellRendererBase.Render(Graphics paint, Rectangle cellRect, String cellValue, CellStyleInfo style, DataColumnBase column, RowColumnIndex rowColumnIndex)
   bei Syncfusion.WinForms.DataGrid.GridPainter.DrawCell(Graphics graphics, Rectangle rect, DataColumnBase column, Object cellValue, String formattedText)
   bei Syncfusion.WinForms.DataGrid.GridPainter.DrawColumn(Graphics graphics, Rectangle finalSize, DataRowBase dataRow, IEnumerable`1 columns)
.......even more information 

An exception "System.ArgumentException" error has occurred in mscorlib.dll.
An item with the same key has already been added.
So i hope i describe the exception well and you can help me.


Mohanram Anbukkarasu [Syncfusion]
Replied On November 29, 2019 01:05 PM UTC

Hi Patrick, 

Thanks for contacting Syncfusion support. 

The reported crash will occur when more than one DetailsViewDefinitions with same RelationalColumn are added to the DataGrid. From the provided code snippet we suspect that within the method FillGridView(false)  you have added DetailsViewDefinition again for the DataGrid with same relational column which is added before. If yes, please clear the DetailsViewDefinition before adding it again as shown in the following code example. 

Code example :  

GridViewDefinition orderDetailsView = new GridViewDefinition(); 
orderDetailsView.RelationalColumn = "OrderDetails"; 
orderDetailsView.DataGrid = childGrid; 

If you are not adding the DetailsViewDefinition with same name within the FillGridView method, Please provide the code used within the FillGridView method and more details about updating the SfDataGrid. It will be helpful for us to find the exact cause for the issue and to provide a  prompt solution at the earliest.  

Mohanram A. 

Replied On November 29, 2019 06:03 PM UTC

Thanks for the answer.
yes, I made a mistake. I just did not see that I called the DetailView on the new load again.
I think that it is solved.

But I have one more question please.
I try to adjust the line height in the DetailView automatically to the content. I used the example:

Add this to the constructor of the form...
List<string> excludeColumns = new List<string>() { "ID", "Name","Klasse" };
autoFitOptions.ExcludeColumns = excludeColumns;

Add this to the constructor of the form... 
DetailView.DataGrid.QueryRowHeight += sfDataGrid_QueryRowHeight;  <------ Where must the event be inserted that it is fired

Add this to the DetailViewLoading method !
DataView.DataGrid.RowHeight = autoHeight;

void sfDataGrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e)
    if (this.sfDataGrid.AutoSizeController.GetAutoRowHeight(e.RowIndex, autoFitOptions, out autoHeight))
        if (autoHeight > 24)
            e.Height = autoHeight;
            e.Handled = true;
Sorry for the simple question, but my experience is not that great yet.

Mohanram Anbukkarasu [Syncfusion]
Replied On December 2, 2019 12:55 PM UTC

Hi Patrick, 

Thanks for the update. 

It is not possible to achieve this requirement. Master-Details view doesn’t support auto row height in SfDataGrid. Please find the limitations of the Master-Details view from the following link.  

Please let us know if you require further other assistance from us.  

Mohanram A. 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon