HELP!一直在努力手动添加带有预填充组合框的DataGridViewRow行。。。DataGridViewComboBoxColumn。我只想让它自动填充字符串、运输选项"地面"、"空中"等。我已经在下拉框中看到了第一个值,但系统显示
System.ArgumentException:DataGridViewComboBoxCell值不是有效的
。。。我从来没能"放下"组合框控件(打开它)我只想制作列,并让它自动填充组合框及其字符串值,但我最近一直在摆弄"DataGridViewComboBoxCell",我希望我最终不需要它。。。谢谢你,我被卡住了!!!
DataGridViewComboBoxCell myCbox = new DataGridViewComboBoxCell(); //TEST TBD
//
if ((dgvMasterPrinting.Columns == null) || (dgvMasterPrinting.Columns.Count < 1))
{
DataGridViewComboBoxColumn dgcShipType = new DataGridViewComboBoxColumn();
//Column SHIP-TO COMBOBOX
dgcShipType.Name = "colComboShip"; //???
//dgcShipType.DataPropertyName = "colComboShip"; //TEST TBD
dgcShipType.HeaderText = "colComboShip";
dgcShipType.DropDownWidth = 90;
dgcShipType.Width = 90;
dgcShipType.MaxDropDownItems = 5;
dgcShipType.DisplayIndex = 5;
dgcShipType.FlatStyle = FlatStyle.Flat;
myCbox.Items.AddRange("A", "N", "P", "S", "Z");
// dgcShipType.Items.AddRange("A", "N", "P", "S", "Z");
//add the other columns (works fine, only the combo box column has problems)
this.dgvMasterPrinting.Columns.Add(dgcShipType);
}
this.dgvMasterPrinting.Rows.Add(...
我做了一个简单的测试:使用设计器制作一个DatagridviewComboBoxColumn并添加项。有趣的是,这导致了一个错误:"DataGridViewComboBoxCell值无效"。。。我在网上看到有人说,有一个固有的MS错误潜伏在。。。
NM我想明白了。。。
DataGridViewComboBoxColumn dgcShipType = new DataGridViewComboBoxColumn();
...
//Column SHIP-TO COMBOBOX
dgcShipType.ReadOnly = false;
dgcShipType.AutoComplete = false;
dgcShipType.DisplayStyleForCurrentCellOnly = true;
dgcShipType.DropDownWidth = 100;
dgcShipType.Width = 110;
dgcShipType.HeaderText = "ShipType";
dgcShipType.Items.AddRange(new object[] { "GROUND", "LOCAL PATIENT", "3-DAY UPS", "2-DAY SERVICE", "PRIORITY OVERNT", "EARLY AM", "WILL CALL" });
dgcShipType.Name = "colComboShip";
dgcShipType.MaxDropDownItems = 7;
dgcShipType.Resizable = System.Windows.Forms.DataGridViewTriState.True;
dgcShipType.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
dgcShipType.DefaultCellStyle.NullValue = "GROUND"; //sets the default display value
dgcShipType.DisplayIndex = 5;
//
...
this.dgvMasterPrinting.Rows.Add(...