Click here to Skip to main content
15,667,014 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to automatically add new records to DataGrid. Everything works, but the DataGrid is refreshing every time. I want to keep it unchanged, only if a new record comes in, I want to add it 

public class Example{
public static ObservableCollection<T> exampleObs = new ...
public void Method()
bool help = true;

  exampleObs.Add(new T(...));


public class XAMLWindow{

 private readonly object exampleLock = new object();
public XAMLWindow{
BindingOperations.EnableCollectionSynchronization(Example.exampleObs, exampleLock);
 lock (exampleLock)
                //DataGridTable.ItemsSource = Example.exampleOb;
                Example ex = null;
                for (int i = 0; i < Example.exampleOb.Count; i++)
                     ex = Example.exampleOb[i];


What I have tried:

Tried to found always the new one. Or add just items(as in example) not ItemSource property.
Gerry Schmitz 27-Jul-22 12:25pm    
If you're "looping and inserting" (an unrealistic exercise) you should be doing a "begin update ... end update" action if you don't want to see "flickering" (a completely predictable result based on what you're doing).
Petr Barabáš 28-Jul-22 3:24am    
Okay, thanks for that. What do you suggest?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900