
I have a gridview with the datasource set to a bindinglist. My goal is for the gridview to accurately reflect changes in the bindinglist’s composition (specifically additions at this point). When I add objects to the bindinglist I get an error saying “Bounds cannot be changed while locked”. I believe this is an issue with the Gridview because if I do not set the datasource, the bindinglist is populated as expected. After a lot of searching I came across a few other posts which were similar to my situation:
However these deal with updating data already present in the bindinglist. My application starts with an empty bindinglist set as the datasource and is populated through code.
My C# .Net 3.5 winforms program uses multiple threads to search through all the directories on the machine and return files that meet certain criteria. The recursive search creates a new thread for each directory found to iterate over it's files:
private static void IndexDirectory(string directory) { foreach (string d in Directory.GetDirectories(directory)) { try { Thread t = new Thread(new ParameterizedThreadStart(GetFiles)); t.Start(d); IndexDirectory(d); } catch(System.UnauthorizedAccessException){ } }}//form field variable used as the datasource for the gridview.BindingList<MyFileObj> bindingList = new BindingList<MyFileObj>();MyCollectionChangedEventHandler(MyEventArgs e){ bindingList.Add( (MyFileObj) e.GetMyFileObj);}When that didn’t work I modified the program to use a backgroundworker and queue hoping that putting the code in the WorkerCompleted method would force it to all execute on the UI thread:
Queue<MyFileObj> addMe = new Queue<MyFileObj>();MyCollectionChangedEventHandler(MyEventArgs e){ addMe.Enqueue ( (MyFileObj) e.GetMyFileObj); if(!backgroundworker.IsBusy) backgroundworker.RunWorkerAsync ();} backgroundworker_DoWork(object sender, DoWorkEventArgs e){ Try{ e.Result = (MyFileObj) addMe.Dequeue(); }Catch() { //queue empty }}backgroundworker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e){ bindingList.Add((MyFileObj) e.Result);}
timSatStart.Value = null;
and it didn't work, i also tried binding a nullable datetime from the database to it and it won't work either.
private DrillDownController drillDownController = new DrillDownController();private DateTime lastSelectedMonth;private void InitializeChart(){ radChartView1.ShowTitle = true; radChartView1.ShowLegend = true; radChartView1.ShowSmartLabels = true; radChartView1.Controllers.Add(drillDownController); radChartView1.Drill += new DrillEventHandler(radChartView1_Drill); radChartView1.ShowDrillNavigation = true; radChartView1.Views.AddNew();}private void radChartView1_Drill(object sender, DrillEventArgs e){ switch (e.Level) { case 0: GroupByMonthYear(e.View); break; case 1: if (e.SelectedPoint != null) lastSelectedMonth = Convert.ToDateTime((e.SelectedPoint.DataItem as System.Data.DataRowView).Row.ItemArray[0]); GroupByDay(e.View, lastSelectedMonth); break; }}
