private List<Class1> Grep()
{
List<Class1> returns = new List<Class1>
{
new Class1{IdNum = _count},
new Class1{IdNum = _count},
new Class1{ IdNum = 1},
new Class1{ IdNum = 1},
new Class1{IdNum = 1},
new Class1{IdNum = 1},
new Class1{IdNum = 1},
};
return returns;
}
dataGridView1.DataSource = null;
dataGridView1.Refresh();
dataGridView1.Update();
private void btnClickStart_Click(object sender, EventArgs e)
{
dataGridView1.DataSource = Grep();
for(int i = 0; i < 10; i++)
{
dataGridView1.DataSource = Grep();
_count++;
Thread.Sleep(300);
}
dataGridView1[0,1].Value = "Какое то новое значение".
dataGridView1.DataSource = Grep();
dataGridView1.Refresh();
dataGridView1.Update();
public class User : INotifyPropertyChanged
{
private string _name;
private int _age;
public string Name
{
get => _name;
set { _name = value; OnPropertyChanged(); }
}
public int Age
{
get => _age;
set { _age = value; OnPropertyChanged(); }
}
public User() { }
public User(string name, int age)
{
Name = name;
Age = age;
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
var itemStates = new List<User>()
{
new User("Анимэшник", 0),
new User("Не анимэшник", 18)
};
var bindingList = new BindingList<User>(itemStates);
var source = new BindingSource(bindingList, null);
dataGridView1.DataSource = source;
await Task.Run(async () =>
{
for (int i = 18; i < 30; i++)
{
await Task.Delay(1000);
itemStates.Where(user => user.Name.Equals("Не анимэшник")).FirstOrDefault().Age = i;
}
});