-1

I am new to WinForms my Main form is multi document interface and there is a new button when i click it Form2 open up (I can open more than one form of type Form2 at the same time)

inside Form2 I have a data Grid View

the question is how can I send any data from any class in the namespace to the data Grid View in Form2

enter image description here

1 Answers1

0

From any class?

I'd use an app-internal message bus, and have the forms subscribe to it and update things as they like.

Googling a bit, it looks like TinyMessenger could be a good option for the message bus. Borrowing e.g. https://stackoverflow.com/a/8560275/51685 for an usage example,

void OnReceiveDataSomewhere(byte[] data) {
    messageHub.Publish(new DataMessage(data));
}
class Form2 {
    // ...
    messageHub.Subscribe<DataMessage>((m) => { UpdateGrid(m.Data); });
AKX
  • 152,115
  • 15
  • 115
  • 172