Eunji Choi
Eunji Choi

Reputation: 15

How to fix 'Key already exists Parameter name: Key' error in UltraGrid?

I wanted to setting Grid Column to coded Grid InitializeLayout Event at the beginning of coding.

UltraGridColumn ugc = null;

ugc = e.Layout.Bands[0].Columns.Add(key,caption);

ugc = e.Layout.Bands[0].Columns.Add(key2, caption2);
ugc.CellAppearance.TextHAlign = HAlign.Left;
ugc.Width = 190;
ugc.LockedWidth = true;

And every time you search, I tried to bind to Grid DataSource by receiving a value from the DB as DataTable.

uGrid.DataSource = dt;

This code caused an error.

Key already exists Parameter name: Key

I don't know what's causing this error. What am I doing wrong?

Upvotes: 0

Views: 1822

Answers (1)

Chandrakant Sabnavis
Chandrakant Sabnavis

Reputation: 66

In the InitializeLayout event check if the column exists before adding. That way it prevents duplicating. //something like this if(!e.Layout.Bands[0].Columns.Exists("key")) e.Layout.Bands[0].Columns.Add(key,caption);

Upvotes: 1

Related Questions