private void InitializationGrid(CLDC_DataCore.Model.DnbModel.DnbGroupInfo MeterGroup) { _DnbGroup = MeterGroup; int _Count = MeterGroup.MeterGroup.Count; if (Data_ZouZi.Rows.Count != _Count) { Data_ZouZi.Rows.Clear(); for (int i = 0; i < _Count; i++) { int RowIndex = Data_ZouZi.Rows.Add(); if ((RowIndex + 1) % 2 == 0) { Data_ZouZi.Rows[RowIndex].DefaultCellStyle.BackColor = CLDC_DataCore.Const.Variable.Color_Grid_Alter; } else { Data_ZouZi.Rows[RowIndex].DefaultCellStyle.BackColor = CLDC_DataCore.Const.Variable.Color_Grid_Normal; } Data_ZouZi.Rows[RowIndex].Cells[0].Style.BackColor = CLDC_DataCore.Const.Variable.Color_Grid_Frone; Data_ZouZi.Rows[RowIndex].Cells[1].Style.BackColor = CLDC_DataCore.Const.Variable.Color_Grid_Frone; } Data_ZouZi.SelectionMode = DataGridViewSelectionMode.FullRowSelect; Data_ZouZi.Refresh(); } }
/// <summary> /// 输入起止码后进行数据合法性检测和自动移动到下一行,这个过程使用了一个委托处理,因为在当前单元格编辑完成后,需要等待表格的CellSelectedChange事件完成后才能处理 /// </summary> /// <param name="RowIndex"></param> /// <param name="ColIndex"></param> private void CellEndEdit(int RowIndex, int ColIndex) { if (ColIndex == 0) { return; } DataGridViewCell Cell = Data_ZouZi.Rows[RowIndex].Cells[ColIndex]; if (!Convert.ToBoolean(Data_ZouZi[0, RowIndex].Value)) { return; } if (Cell.Value == null || !CLDC_DataCore.Function.Number.IsNumeric(Cell.Value.ToString())) { MessageBoxEx.Show(this, "起码或止码必须是一个数字,请重新输入...", "输入错误", MessageBoxButtons.OK, MessageBoxIcon.Error); Data_ZouZi.Rows[RowIndex].Cells[ColIndex].Selected = true; Data_ZouZi.Rows[RowIndex].Cells[ColIndex].Value = ""; Data_ZouZi.BeginEdit(true); return; } else { for (int i = RowIndex + 1; i < Data_ZouZi.Rows.Count; i++) { if (Convert.ToBoolean(Data_ZouZi[0, i].Value)) { Data_ZouZi[ColIndex, i].Selected = true; Data_ZouZi.BeginEdit(true); break; } } } }
private void Data_ZouZi_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e) { if (CLDC_DataCore.Const.GlobalUnit.CheckState != CLDC_Comm.Enum.Cus_CheckStaute.停止检定) { return; } if (e.ColumnIndex != 0 || e.RowIndex == -1) { if (e.RowIndex >= 0 && e.ColumnIndex >= 0) { try { this.GridSelectRowIndexChanged(e.RowIndex); } catch { } } return; //如果不是第一列,则退出 } try { this.GridSelectRowIndexChanged(e.RowIndex); } catch { } if (Data_ZouZi[e.ColumnIndex, e.RowIndex].ReadOnly) { return; //如果是只读则退出! } if (ParentMain.Evt_OnYaoJianChanged != null) { bool Yn; if ((bool)Data_ZouZi.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) { Yn = false; Data_ZouZi.EndEdit(); } else { Yn = true; Data_ZouZi.EndEdit(); } Data_ZouZi.Enabled = false; //Comm.Function.TopWaiting.ShowWaiting("正在更改..."); ParentMain.Evt_OnYaoJianChanged(_TaiType, _TaiID, e.RowIndex, Yn); //Comm.Function.TopWaiting.HideWaiting(); } else { MessageBoxEx.Show(this, "没有处理事件Evt_OnYaoJianChanged", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }