HELP!一直在努力手动添加DataGridViewRow行与预先填充的组合框...准确的DataGridViewComboBoxColumn。我只是想让它自动填充字符串,运输选项“地面”,“空气”等。我已经看到下拉框中的第一个值,但系统说
System.ArguementException: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并添加项目。有趣的是,这会导致错误:'theDataGridViewComboBoxCell值无效'...我在www上看到有一个固有的MS错误潜伏在...内...
答案 0 :(得分:0)
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(...