我想从datagridview获取数据,然后使用包含字符串的对象数组中的数据填充组合框
public class Departmentinfo
{
public string departmentname;
.
.
.
.
}
Departmentinfo dep[];
private void getdepartments()
{
for (int i = 0; i < dataGridView1.RowCount; i++)
{
college.department[i].departmentname = Convert.ToString(dataGridView1.Rows[i].Cells[0].Value);
}
}
private void putdepinfo()
{
comboBox4.DataSource = dep[].departmentname;
}
请建议!
答案 0 :(得分:0)
我得到了代码,
public class Departmentinfo
{
public string departmentname;
private void Departmentinfo(string s)
{
this.departmentname = s;
}
}
List<Departmentinfo> DepInfo = new List<Departmentinfo>();
private void getdepartments()
{
for (int i = 0; i < dataGridView1.RowCount; i++)
{
DepInfo.Add(new Departmentinfo(Convert.ToString(dataGridView1.Rows[i].Cells[0].Value)));
}
}
private void putdepartments()
{
foreach (Departmentinfo dep in DepInfo)
{
comboBox4.Items.Add(dep.departmentname);
}
}