[英]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.