void Bind() { loadState = false; DgvItemInfo.Rows.Clear(); string shipType = "1"; decimal status = 10; if (RB0.Checked) { status = 0; } else { status = 10; } if (RBUnnormal.Checked) { shipType = "1"; } else { shipType = "0"; } itemInfos = ItemClass.GetItemInfo(box_type.SelectedIndex, shipType, status, txt_keywd.Text.Trim()); DgvItemInfo.AutoGenerateColumns = false; //DgvItemInfo.DataSource = itemInfos foreach (var item in itemInfos) { DataGridViewCellStyle dgvStyle = new DataGridViewCellStyle(); dgvStyle.BackColor = Color.LightGreen; // 存了状态值 int index = this.DgvItemInfo.Rows.Add(); this.DgvItemInfo.Rows[index].Cells[0].Value = item.ItemNo; this.DgvItemInfo.Rows[index].Cells[1].Value = item.ItemName; this.DgvItemInfo.Rows[index].Cells[2].Value = item.BigBox_Bar; if (item.Shiptype == "0") { this.DgvItemInfo.Rows[index].Cells[3].Value = false; } else if (item.Shiptype == "1") { this.DgvItemInfo.Rows[index].Cells[3].Value = true; } else { item.Shiptype = "0"; list.Add(item); dgvStyle.BackColor = Color.Yellow; this.DgvItemInfo.Rows[index].Cells[3].Value = false; for (int i = 0; i < DgvItemInfo.Rows[index].Cells.Count; i++) { DgvItemInfo.Rows[index].Cells[i].Style = dgvStyle; } } //this.DgvItemInfo.Rows[index].Cells[4].Value = item.RowStatus; if (item.RowStatus == 10) { this.DgvItemInfo.Rows[index].Cells[4].Value = true; } else { this.DgvItemInfo.Rows[index].Cells[4].Value = false; } this.DgvItemInfo.Rows[index].Cells[5].Value = item.ILength; this.DgvItemInfo.Rows[index].Cells[6].Value = item.IWidth; this.DgvItemInfo.Rows[index].Cells[7].Value = item.IHeight; this.DgvItemInfo.Rows[index].Cells[8].Value = item.JT_Size; } DgvItemInfo.EndEdit(); loadState = true; }