I have a standard C# queue, declared like this:
private Queue<DeployJob> _solutionQueue = new Queue<DeployJob>();
Now I want to bind this queue to an DataGridView, which is placed inside a winform. With “bind” i mean that everytime i dequeue or enqueue an item from the queue the DataGridView gets updated (so that it always represents the state of the queue).
I have tried to bind it this way:
jobGridView.DataSource = _solutionQueue;
But it doesnt work, even if I use the update or refresh methods. If you need more code, please feel free to ask 🙂
According to MSDN, the
DataGridView.DataSourcemust implement one of the following interfaces:IListIListSourceIBindingListIBindingListViewThe
Queue<T>class implements parent interfaces ofIList, includingIEnumerableandICollection, but notIListitself.One suggestion is to use LINQ to create a
List<DeployJob>from the queue and bind like so:You would want to make sure and handle any events that update/modify the queue, and re-bind the DataGridView to a newly created List