1

これを行う方法gridviewcomboboxcolumnsでこれを行う方法任意のアイデアplx

//フォーム読み込みイベント

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つのコンボックスがgridviewCombobox列であると仮定して、これをgridviewcombobox列で機能させる方法

Project in Windows Form in C#
4

1 に答える 1

0

answer問題に直面している人々の助けになるので、数か月後にこれを投稿します。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";

                }
于 2014-02-22T21:27:31.953 に答える