简体   繁体   English

如何修复UltraGrid中的“键已存在,参数名称:键”错误?

[英]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. 我想在编码开始时将Grid Column设置为已编码的Grid InitializeLayout Event。

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. 每次您搜索时,我都试图通过从DB接收一个作为DataTable的值来绑定到Grid DataSource。

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? 我究竟做错了什么?

In the InitializeLayout event check if the column exists before adding. 在InitializeLayout事件中,在添加之前检查该列是否存在。 That way it prevents duplicating. 这样可以防止重复。 //something like this if(!e.Layout.Bands[0].Columns.Exists("key")) e.Layout.Bands[0].Columns.Add(key,caption); //类似于这样的东西if(!e.Layout.Bands[0].Columns.Exists("key")) e.Layout.Bands[0].Columns.Add(key,caption);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 代号为“ XX”的设置键已存在 - The settings key with code name 'XX' already exists 如何修复'值不能是 null。 参数名称:c#中的Key'error - How to fix 'Value cannot be null. Parameter name: Key' error in c# 如何检查容器中是否已存在密钥? - How to check if a key already exists in container? 我收到此错误我该如何解决:它已经添加了具有相同密钥的项目。 钥匙:1 - I got this error how i can fix: it An item with the same key has already been added. Key: 1 具有相同密钥的项目已存在 - item with same key already exists 具有相同键的条目已存在 - An entry with the same key already exists 解决“在ObjectStateManager中已经存在具有相同键的对象”的最佳实践错误 - Best Practice for Solve “An object with the same key already exists in the ObjectStateManager” Error EF6 中的关系错误外键已存在 - Foreign Key already exists For Relation Error in EF6 错误ObjectStateManager中已经存在具有相同键的对象。 使用ViewModel - Error An object with the same key already exists in the ObjectStateManager. with ViewModel Ef core code first Error: Key ("Id")=(33) already exists - Ef core code first Error : Key ("Id")=(33) already exists
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM