c# - DataGridView not updating in UI when underlying datasource changes -


I am creating a small Windows application application that will receive messages from a background thread and then add them to a list on the menu. Will give the form I DataSource DataGrid view message list ( like list & lt; message & gt; ) on the form >

At this time, messages are accumulating, but I can not get DataGridView to deliver these messages, as they are generated. Here I have given a summary of the approach used.

1. Start setting primarily binding and beginning the message

  Internal Home (IMages Dispatcher Message Dispatcher, IMSJP Publisher Message Publisher) {Initialization (); _messageEntries = New list & lt; Message & gt; (); BindToMessageEntriesList (); _messageDispatcher = messageDispatcher; _messageDispatcher.OnMessageReceived + = MessageDispatcher_OnMessageReceived; _messageDispatcher.Start (); } Private Zero BindToMessageEntriesList () {MessageIntegrated.Data Source = _messageEntries; }   

2. Add process to received messages and internal list

  Private Zero MessageDispatcher_OnMessageReceived (message message) {lock (_logEntries) {_messageEntries.Add (message); } Var cb = new refreshlist callback (RefreshView); This.Invoke (CB); }   

3. Refresh to main thread

  Private Zero Refresh View () {MessageEntriesGrid.Refresh (); }   

Can anyone suggest how I can reflect the changes that occur in the UI.

Note: I have also tried to use invalid method and reset method. I list a ObsavableCollection

switch Tried to do list & lt; Message & gt; () for a custom class and binding list and attach your message dispatcher to it. Example Public class message list: bidding list and message; Message & gt; {}

Event by changing the list in your main form and you're good to go.

Comments