2014-07-19 76 views
-1

我想從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

是否使用VB6? –

+0

@ user3003216沒有VB10 –

回答

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); 
    } 
} 
+0

就像一個魅力... – InferOn