WinForms: How to handle DataGridViewButtonColumn click event

There’s not a direct way to handle the DataGridViewButtonColumn button click event. Instead, you have to: Handle the DataGridView.CellContentClick event. Check if they clicked the button column. Execute the button click handling logic, passing in the bound data item. In this article I’ll show a step-by-step example of how to handle the button click. Example … Read more WinForms: How to handle DataGridViewButtonColumn click event

C# – Pass in a Func to override behavior

If I want to change the behavior of a method from the outside, I can pass in a function pointer. This approach exists in every language, and is one way to implement the Strategy Pattern. In C#, function pointers are referred to as delegates, and the two most common ones are Action and Func. The … Read more C# – Pass in a Func to override behavior

Event-driven .NET: Concurrent Producer/Consumer using BlockingCollection

With the Producer/Consumer pattern you have one or more threads producing new work and enqueuing it, and one or more threads consuming that work by dequeuing it and processing it. The consumers and producers share access to the work queue. Think of it like the Post Office. You have one or more people (producers) dropping … Read more Event-driven .NET: Concurrent Producer/Consumer using BlockingCollection

Event-driven .NET: How to add an event to a class

In the previous article we saw how events work. In this article I’ll show how to add an event to a class. In order to illustrate this I’ve created a simple chat app that uses an in-memory message queue. Each chat window is subscribed to the message queue’s OnMessageReceived event, and updates their UI upon … Read more Event-driven .NET: How to add an event to a class

Event-driven .NET: how events work

The very basis of event-driven programming is the concept of events. Events are an implementation of the Observer Pattern. With the Observer Pattern you have an observable entity and entities that want to observe that entity. Objects with events are observable, and other objects subscribe to those events and are notified when the events happen. … Read more Event-driven .NET: how events work