これは、datagridview を作成してから 2 つのコンボボックスを追加するために使用している方法です。3 つの DataTables が他のクラスから読み込まれます。
public void GetWorkorderItems()
{
Workorders wo = new Workorders();
ItemTable = wo.LoadWorkorderItemsTable(_ID);
this.datagridWorkorderItems.DataSource = ItemTable;
this.datagridWorkorderItems.AutoGenerateColumns = true;
this.datagridWorkorderItems.Columns[0].Visible = false;
this.datagridWorkorderItems.Columns[1].HeaderText = "Qty";
this.datagridWorkorderItems.Columns[1].Width = 100;
this.datagridWorkorderItems.Columns[2].HeaderText = "Part";
this.datagridWorkorderItems.Columns[2].Width = 100;
this.datagridWorkorderItems.Columns[3].HeaderText = "Labor";
this.datagridWorkorderItems.Columns[3].Width = 100;
this.datagridWorkorderItems.Columns[4].HeaderText = "Price";
this.datagridWorkorderItems.Columns[4].Width = 150;
this.datagridWorkorderItems.Columns[5].HeaderText = "Description";
this.datagridWorkorderItems.Columns[5].Width = 150;
Parts part = new Parts();
DataTable partdata = new DataTable();
partdata = part.LoadPartTable();
DataGridViewComboBoxColumn pcb = (DataGridViewComboBoxColumn)this.datagridWorkorderItems.Columns[2];
pcb.DataSource = partdata;
pcb.DisplayMember = "PartName";
pcb.ValueMember = "PartID";
datagridWorkorderItems.Columns.Add(pcb);
Labor labor = new Labor();
DataTable data = new DataTable();
data = labor.LoadLaborTable();
DataGridViewComboBoxColumn cb = (DataGridViewComboBoxColumn)this.datagridWorkorderItems.Columns[3];
cb.DataSource = data;
cb.DisplayMember = "LaborItem";
cb.ValueMember = "LaborID";
datagridWorkorderItems.Columns.Add(cb);
}
コードが DataGridViewComboBox オブジェクトの作成に達すると、コードはメソッドを終了し、コンボボックスを追加またはロードしません。スローされる例外もありません。
何か助けはありますか?
EDIT* * ** DataGridViewTextBoxColumn col0 = (DataGridViewTextBoxColumn)this.datagridWorkorderItems.Columns[0]; this.datagridWorkorderItems.Columns[0].DataPropertyName = "WOItemID"; this.datagridWorkorderItems.Columns[0].Visible = false; this.datagridWorkorderItems.Columns.Add(col0);
DataGridViewTextBoxColumn col1 = (DataGridViewTextBoxColumn)this.datagridWorkorderItems.Columns[1];
this.datagridWorkorderItems.Columns[1].DataPropertyName = "Quantity";
this.datagridWorkorderItems.Columns[1].HeaderText = "Qty";
this.datagridWorkorderItems.Columns[1].Width = 100;
this.datagridWorkorderItems.Columns.Add(col1);
DataGridViewComboBoxColumn pcb = (DataGridViewComboBoxColumn)this.datagridWorkorderItems.Columns[2];
pcb.DataSource = partdata;
pcb.DisplayMember = "PartName";
pcb.ValueMember = "PartID";
datagridWorkorderItems.Columns.Add(pcb);
私が理解していれば、これが列を構築する方法かもしれません。
***動作する固定コード* ** * **
public void GetWorkorderItems()
{
Workorders wo = new Workorders();
ItemTable = wo.LoadWorkorderItemsTable(_ID);
Parts part = new Parts();
DataTable partdata = new DataTable();
partdata = part.LoadPartTable();
Labor labor = new Labor();
DataTable data = new DataTable();
data = labor.LoadLaborTable();
this.datagridWorkorderItems.AutoGenerateColumns = false;
DataGridViewTextBoxColumn col0 = new DataGridViewTextBoxColumn();
col0.DataPropertyName = "WOItemID";
col0.Visible = false;
this.datagridWorkorderItems.Columns.Add(col0);
DataGridViewTextBoxColumn col1 = new DataGridViewTextBoxColumn();
col1.DataPropertyName = "Quantity";
col1.HeaderText = "Qty";
col1.Width = 100;
this.datagridWorkorderItems.Columns.Add(col1);
DataGridViewComboBoxColumn col2 = new DataGridViewComboBoxColumn();
col2.DataPropertyName = "PartID";
col2.DataSource = partdata;
col2.DisplayMember = "PartName";
col2.ValueMember = "PartID";
col2.HeaderText = "Part";
datagridWorkorderItems.Columns.Add(col2);
DataGridViewComboBoxColumn col3 = new DataGridViewComboBoxColumn();
col3.DataPropertyName = "LaborID";
col3.DataSource = data;
col3.DisplayMember = "LaborItem";
col3.ValueMember = "LaborID";
col3.HeaderText = "Labor";
datagridWorkorderItems.Columns.Add(col3);
DataGridViewTextBoxColumn col4 = new DataGridViewTextBoxColumn();
col4.DataPropertyName = "Price";
col4.HeaderText = "Price";
col4.Width = 100;
this.datagridWorkorderItems.Columns.Add(col4);
DataGridViewTextBoxColumn col5 = new DataGridViewTextBoxColumn();
col5.DataPropertyName = "Description";
col5.HeaderText = "Description";
col5.Width = 100;
this.datagridWorkorderItems.Columns.Add(col5);
this.datagridWorkorderItems.DataSource = ItemTable;
}