foreach gives startindex 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.
精彩评论