private void toolStripButtonDefine_Click(object sender, EventArgs e) { if (null == FormDefine) { FormDefine = new FormDefine(); FormDefine.LoadDefine(); // Dialog 模式不需要同步更新数据,简单点,先这个方案。 FormDefine.ShowDialog(this); FormDefine.Dispose(); FormDefine = null; foreach (var gridReload in ReloadGridsAfterFormDefineClosed) { var firstDisplayCellCol = -1; var firstDisplayCellRow = -1; if (null != gridReload.FirstDisplayedCell) { firstDisplayCellCol = gridReload.FirstDisplayedCell.ColumnIndex; firstDisplayCellRow = gridReload.FirstDisplayedCell.RowIndex; } var currentCellCol = -1; var currentCellRow = -1; if (null != gridReload.CurrentCell) { currentCellCol = gridReload.CurrentCell.ColumnIndex; currentCellRow = gridReload.CurrentCell.RowIndex; } gridReload.SuspendLayout(); var doc = gridReload.Tag as Document; doc.GridData.View = null; doc.BuildGridData(); doc.GridData.VerifyAll(false); doc.GridData.View = gridReload; doc.GridData.SyncToView(); // resore view. var firstDisplayCellNow = GetSafeCell(gridReload, firstDisplayCellCol, firstDisplayCellRow); if (null != firstDisplayCellNow) { gridReload.FirstDisplayedCell = firstDisplayCellNow; } var currentCellNow = GetSafeCell(gridReload, currentCellCol, currentCellRow); if (null != currentCellNow) { gridReload.CurrentCell = currentCellNow; } gridReload.ResumeLayout(); } if (tabs.SelectedTab != null) { DataGridView grid = tabs.SelectedTab.Controls[0] as DataGridView; if (false == ReloadGridsAfterFormDefineClosed.Contains(grid)) // 如果已经Reload过,就不需要再次VerifyAll。 { grid.SuspendLayout(); (grid.Tag as Document).GridData.VerifyAll(true); grid.ResumeLayout(); } } ReloadGridsAfterFormDefineClosed.Clear(); Documents.CloseNotDependsByView(); // 同时显示两个窗口,需要同步数据。不是先这种方案了。 // FormDefine.Show(); } else { FormDefine.BringToFront(); } }
private void tabs_SelectedIndexChanged(object sender, EventArgs e) { FormDefine?.LoadDefine(); }