2013-09-10 15 views
1

Как сделать эту работу на gridviewcomboboxcolumns любую идею PLXdatagridviewcombobox столбцов зависит от другого столбца

// Форма загрузки события

string query="select article_name from article"; 
SqlCommmand cmd = new SqlCommand(query,con); 
SqlDataAdapter da= new SqlDataAdapter(cmd); 
DataTable dt=new DataTable(); 
da.Fill(dt); 
combobox1.items.clear(); 
for(int i=0;i<dt.rows.count;i++) 
{ 
combobox1.items.add(dt.rows[i].cells[0].toString()); 
} 

\ ComboBox1 Выбранный IndexChange событие

string query1="select description from article where article_name='"+combobox1.selectedItem.ToString()+"'"; 
SqlCommmand cmd1 = new SqlCommand(query1,con); 
SqlDataAdapter da1= new SqlDataAdapter(cmd); 
DataTable dt1=new DataTable(); 
da1.Fill(dt1); 
combobox2.items.clear(); 
for(int i=0;i<dt1.rows.count;i++) 
{ 
combobox2.items.add(dt1.rows[i].cells[0].toString()); 
} 

\ Предположим теперь эти 2 COMBOX является gridviewCombobox Столбцы, так как сделать эту работу на gridviewcombobox колонн

Project in Windows Form in C# 
+0

же проблема братан и я также нуждаются в этом – naeemshah1

ответ

0

Я м отправляю эту answer после нескольких месяцев, потому что его помогает для thoose whoose сталкиваясь с проблемой на DataGridviewComboboxcell Я сделал свое мастерство Сначала заполните мою первую/главную колонку

SqlCommand objCmd = new SqlCommand("select distinct article_name from Setup_article_custominvoice", con); 
        SqlDataAdapter objDA = new SqlDataAdapter(objCmd); 
        objDA.SelectCommand.CommandText = objCmd.CommandText.ToString(); 
        DataTable dt = new DataTable(); 
        objDA.Fill(dt); 
        article.DataSource = dt; 
        //this column1 will display as text 
        article.DisplayMember = "article_name"; 

После того, что я собирался на Cell End Edit

if (dataGridView1.CurrentCell == dataGridView1.CurrentRow.Cells["article_name"]) 
       { 
        string CategoryValue = ""; 
        //string CategoryValue1 = ""; 

        if (dataGridView1.CurrentCell.Value != null) 
        { 
         CategoryValue = dataGridView1.CurrentCell.Value.ToString(); 
         //CategoryValue1 = dataGridView1.CurrentCell.Value.ToString(); 
        } 
        //SqlConnection objCon = new SqlConnection(@"Data Source=.\SqlExpress;Initial Catalog=dbTest3;Integrated Security=True"); 
        string query = "select article_name,composition from Setup_article_custominvoice where article_name='" + CategoryValue + "'"; 
        SqlCommand objCmd = new SqlCommand(query, con); 

        SqlDataAdapter objDA = new SqlDataAdapter(objCmd); 

        objDA.SelectCommand.CommandText = objCmd.CommandText.ToString(); 
        DataTable dt = new DataTable(); 

        objDA.Fill(dt); 

        DataGridViewComboBoxCell t = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[2] as DataGridViewComboBoxCell; 
        t.DataSource = dt; 
        t.DisplayMember = "composition"; 

       } 
Смежные вопросы