开发者

foreach gives startindex error

开发者 https://www.devze.com 2023-03-25 11:23 出处:网络
following code gives a \"Value of \'7\' is not valid for \'indexStart\'. \'indexStart\' must be less than or equal to 3. Parameter name: indexStart\" error!

following code gives a "Value of '7' is not valid for 'indexStart'. 'indexStart' must be less than or equal to 3. Parameter name: indexStart" error!

void eventsource_EventLogCollectionChanged(object sender, EventLogEventArgs e)
        {
            _all.AddRange(e.NewEventLogItems);

            BindingList<EventlogItem> data = dgvPlcEvents.DataSource as BindingList<EventlogItem>;
            List<EventlogItem> newdata = FilterEvents((EventLogItemType)cboEventTypes.SelectedItem, GetSidFilter(), e.NewEventLogItems).ToList();
            foreach(EventlogItem item in newdata)
            {
                data.Add(item);
            }

            dgvPlcEvents.Invalidate();
        }

1) Why? 2) how can I fix it?

I transfered the bindinglist (getting from filterevents) to a list to avoid the error but it didn't helped.

What a开发者_开发百科m I doing wrong? I just want to add some items to a bindinglist that is the datasource for a datagridview so it would auto insert rows.

Thanks


You are getting this error because your datasource is set to AllowNew = true; set it to AllowNew = false; then add your item.

0

精彩评论

暂无评论...
验证码 换一张
取 消