データテーブルから 1 つの列を取得して、グリッド ビューにコンボ ボックスとして表示しようとしています。また、選択できる小さなコレクションでコンボを埋める機能も必要です。GUIからバインドすると値が表示されないため、プログラムで試していますが、正しいコードが見つからないようです。
connection2 = new MySqlConnection(ConnectionString2);
try
{
string proid = txtbxProjId.Text;
//prepare query to get all records from items table
string query2 = "select sl.sample_id As sample_id, sl.sample_number As Sample_Number, sl.sample_date As Sample_Date, sl.sample_time As Sample_Time, sl.sample_comments As Sample_Comments FROM spt_sample_login sl Where project_id = '"+proid+"'";
//prepare adapter to run query
adapter2 = new MySqlDataAdapter(query2, connection2);
adapter3 = new MySqlDataAdapter(query2, connection2);
//create a DataTable to hold the query results
DataTable dTable2 = new DataTable();
DataSet DS2 = new DataSet();
//fill the DataTable
//get query results in dataset
adapter2.Fill(dTable2);
adapter3.Fill(DS2);
//return datatable with all records
//BindingSource to sync DataTable and DataGridView
//set the BindingSource DataSource
GridView1.DataSource = dTable2;
this.GridView1.Columns["sample_id"].Visible = false;
this.GridView1.Columns["Sample_Type"].DisplayIndex = 4;
this.GridView1.Columns["Sample_Type"].Visible = true;
//set the DataGridView DataSource
}
catch (MySqlException ex)
{
}
}
これは機能しますが、Sample_Type をテキスト ボックスとして表示し、F、PQ、B をオプションとして組み合わせて表示します。
ありがとうブレント