【问题标题】:Get Data from DatagridView from to Object Array then populate ComboBox从 DatagridView 获取数据到对象数组,然后填充 ComboBox
【发布时间】:2014-07-19 06:13:55
【问题描述】:
我想从 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;
}
请推荐!
【问题讨论】:
标签:
c#
arrays
object
datagridview
combobox
【解决方案1】:
我得到了处理这个的代码,
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);
}
}