Binding DataGridView in windows forms to a list<List<T>>

半城伤御伤魂 提交于 2019-12-02 04:59:52

Presuming that your nested list has been populated, and in addition to your DataGridView, your form has a Previous and Next button for changing pages: you could use the buttons to change an index which indicates which nested list is to be used as the DataSource.

public List<List<MyObject>> Pages { get; set; } // Populated elsewhere...
public int PageIndex { get; set; }

private void ChangePage()
{
  this.PreviousButton.Enabled = this.PageIndex > 0;
  this.NextButton.Enabled = this.PageIndex < this.Pages.Count - 1;
  this.dataGridView1.DataSource = this.Pages[this.PageIndex];
}

private void PreviousButton_Click(object sender, EventArgs e)
{
  this.PageIndex--;
  this.ChangePage();
}

private void NextButton_Click(object sender, EventArgs e)
{
  this.PageIndex++;
  this.ChangePage();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!