private void InitStation() { m_mapSubCenterPage = new Dictionary <int, CDataGridTabPage>(); m_tabControl.SuspendLayout(); m_dgvAllPage = new CDataGridTabPage() { Title = "所有站点", BTabRectClosable = false }; m_dgvAllPage.DataGrid = new CDataGridViewSoilRTD() { AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill }; m_dgvAllPage.Padding = new System.Windows.Forms.Padding(0, 0, 0, 3); m_tabControl.AddPage(m_dgvAllPage); // 添加分中心 List <CEntitySubCenter> listSubCenter = CDBDataMgr.Instance.GetAllSubCenter(); for (int i = 0; i < listSubCenter.Count; ++i) { CDataGridTabPage tmp = new CDataGridTabPage() { Title = listSubCenter[i].SubCenterName, BTabRectClosable = false }; m_mapSubCenterPage.Add(listSubCenter[i].SubCenterID, tmp); tmp.DataGrid = new CDataGridViewSoilRTD() { AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill }; tmp.Padding = new System.Windows.Forms.Padding(0, 0, 0, 3); m_tabControl.AddPage(tmp); //(tmp.DataGrid as CDataGridViewSoilRTD).RecalculateHeaderSize(); //计算表头宽度 } // 绑定消息,分中心变更消息 CDBDataMgr.Instance.SubCenterUpdated += new EventHandler(this.EHSubCenterChanged); // 收到RTD消息 CDBSoilDataMgr.Instance.RecvedRTDSoilData += new EventHandler <CEventSingleArgs <CEntitySoilData> >(EHRecvRTD); // 收到清空RTD消息 CDBSoilDataMgr.Instance.RTDSoilDataClear += new EventHandler(EHClearRTD); m_tabControl.ResumeLayout(false); // 开启定时器 m_timer.Start(); //(m_dgvAllPage.DataGrid as CDataGridViewSoilRTD).RecalculateHeaderSize(); }
private void EHSubCenterChanged(object sender, EventArgs e) { // 重新刷新界面 m_tabControl.SuspendLayout(); Dictionary <int, CDataGridTabPage> oldMap = m_mapSubCenterPage; m_mapSubCenterPage = new Dictionary <int, CDataGridTabPage>(); // 删除原先的分中心页面 foreach (KeyValuePair <int, CDataGridTabPage> item in oldMap) { m_tabControl.RemovePage(item.Value); } // 建立新的分中心页面 // 添加分中心 List <CEntitySubCenter> listSubCenter = CDBDataMgr.Instance.GetAllSubCenter(); for (int i = 0; i < listSubCenter.Count; ++i) { CDataGridTabPage tmp = new CDataGridTabPage() { Title = listSubCenter[i].SubCenterName, BTabRectClosable = false }; tmp.Padding = new System.Windows.Forms.Padding(0, 0, 0, 3); m_mapSubCenterPage.Add(listSubCenter[i].SubCenterID, tmp); if (oldMap.ContainsKey(listSubCenter[i].SubCenterID)) { //Debug.WriteLine("before-{0}:{1}", i,oldMap[listSubCenter[i].SubCenterID].DataGrid.Width); //int width = oldMap[listSubCenter[i].SubCenterID].DataGrid.Width; oldMap[listSubCenter[i].SubCenterID].RemoveDataGrid(); // 内容不均匀分布问题 oldMap[listSubCenter[i].SubCenterID].DataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; tmp.DataGrid = oldMap[listSubCenter[i].SubCenterID].DataGrid; tmp.DataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; //Debug.WriteLine("after-{0}:{1}", i,tmp.DataGrid.Width); //tmp.DataGrid.Width = width; } else { // 新建数据项 tmp.DataGrid = new CDataGridViewSoilRTD(); tmp.DataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; } m_tabControl.AddPage(tmp); } m_tabControl.ResumeLayout(false); }