我想通过使用新的BindingSource每次计数器增加新行时添加 但它添加了行"最后一次修改"
这是我的代码:
public class PacketWrapper
{
public string p;
public int Count { get; set; }
public string Timeval { get { return "l"; } }
public string LinkLayerType { get { return"2"; } }
public int Length { get { return p.Length; } }
public PacketWrapper(int count, string p)
{
this.Count = count;
this.p = p;
}
}
BindingSource bs = new BindingSource();
PacketWrapper p;
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.DataSource = bs;
p = new PacketWrapper(1, "djd");
Timer MyTimer = new Timer();
MyTimer.Interval = (450); // 45 mins
MyTimer.Tick += new EventHandler(MyTimer_Tick);
MyTimer.Start();
}
private void MyTimer_Tick(object sender, EventArgs e)
{
for (int i = 1; i < 11; i++)
{
p.Count = i;
bs.DataSource = p;
}
}
如何使用此代码每次添加新行?
答案 0 :(得分:0)
替换
bs.DataSource = p;
带
bs.Add(p);