[英]How can I divide strings into different datagridview
这就是我以编程方式添加 dataGridview 的方式
DataGridView grid = new DataGridView();
grid.Location = new Point(5, 30);
grid.Width = container.Width - 10;
grid.Height = container.Height - 40;
grid.Name = "Section " + countSections.ToString();
grid.Columns.Add("StudentID", "StudentID");
grid.Columns.Add("StudentName","StudentName");
container.Controls.Add(grid);
现在我们假设我们有 5 个 dataGridView
//I have list of students
string [] names = {"name","name2","name3","name4","name5","name6"};
//This is how I indentify DGV
foreach (Control grid in Pan.Controls)
{
if (grid is DataGridView)
{
DataGridView myGrid = grid as DataGridView;
//here how can i divide those names in different datagridview
//I use this syntax to add rows
mygrid.Rows.Add(studentId,names);
}
}
给你一个想法这个模块我称之为自动切片,抱歉逻辑和想法
您需要通过获取其枚举器 amnd 来迭代您的names
数组,然后在每次将名称添加到 DataGrid 时对其调用 MoveNext。
//I have list of students
string [] names = {"name","name2","name3","name4","name5","name6"};
// enumerator
var nameEnumerator = names.GetEnumerator();
//This is how I indentify DGV
foreach (Control grid in Pan.Controls)
{
if (grid is DataGridView)
{
DataGridView myGrid = grid as DataGridView;
// check if we still have names
if (nameEnumerator.MoveNext())
{
mygrid.Rows.Add(studentId, nameIterator.Current);
}
}
}
//I have list of students
string [] names = {"name","name2","name3","name4","name5","name6"};
//This is how I identify DGV
int nameIndex=0;
foreach (Control grid in Pan.Controls)
{
if (grid is DataGridView)
{
DataGridView myGrid = grid as DataGridView;
//here how can i divide those names in different datagridview
//I use this syntax to add rows
mygrid.Rows.Add(studentId,names[nameIndex++]);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.