private void format_grid() { int i; string[] caption = new string[5]; for (i = 0; i <= 4; i++) { caption[i] = m_fg.Cols[i].Caption.ToString(); } // Initialize the control. m_fg.Styles.Normal.WordWrap = true; // m_fg.Cols.Count = 9; m_fg.Rows.Insert(0); m_fg.Rows.Fixed = 2; m_fg.AllowMerging = C1.Win.C1FlexGrid.AllowMergingEnum.FixedOnly; // Create row headers. m_fg.Rows[0].AllowMerging = true; // Merge the four cells with same contents. C1.Win.C1FlexGrid.CellRange rng = m_fg.GetCellRange(0, 4, 0, 5); rng.Data = "Số lượng đã bổ nhiệm nhưng chưa có quyết định"; // Merge the four cells with same contents. //rng = m_fg.GetCellRange(0, 5, 0, 8); //rng.Data = "South"; /*for ( i = 1 ; i <= 4; i++) * { * m_fg[1,i] = "Qtr " + i; * m_fg[1, i + 4] = "Qtr " + i; * } */ // Create the column header. for (i = 0; i <= 3; i++) { m_fg.Cols[i].AllowMerging = true; rng = m_fg.GetCellRange(0, i, 1, i); rng.Data = caption[i].ToString(); } // Merge the two cells with same contents. // Align and autosize the cells. m_fg.Styles.Fixed.TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter; //m_fg.AutoSizeCols(0,m_fg.Cols.Count-1,10); }
private void c1FlexGrid1_AfterSelChange(object sender, RangeEventArgs e) { cRange = e.NewRange; }
/// <summary> /// Event used to finish up the Copying process /// Currently it handles only String, Int and DateTime values /// </summary> void fg_MouseUp(object sender, MouseEventArgs e) { if (fg.Cursor == Cursors.Cross) { if (ModifierKeys == Keys.Control) { C1.Win.C1FlexGrid.CellRange rg = fg.Selection; Object data = startCell.Data; if (data != null) { Type actualDataType = GetDataType(data); int stepValue = 0; int rowCount = 0; int colCount = 0; if (rg.r1 != rg.r2) { if (rg.r2 > rg.r1) { stepValue = 1; } else if (rg.r2 < rg.r1) { stepValue = -1; } if (stepValue == 1) { rowCount = rg.r2 - rg.r1; } else if (stepValue == -1) { rowCount = rg.r1 - rg.r2; } } else { if (rg.c2 > rg.c1) { stepValue = 1; } else if (rg.c2 < rg.c1) { stepValue = -1; } if (stepValue == 1) { colCount = rg.c2 - rg.c1; } else if (stepValue == -1) { colCount = rg.c1 - rg.c2; } } if (actualDataType == typeof(int)) { int val; bool typeFlag = int.TryParse(data.ToString(), out val); if (rowCount > colCount) { for (int i = 1; i <= rowCount; i++) { fg.SetData(rg.r1 + (i * stepValue), rg.c1, val + (i * stepValue)); } } else { for (int i = 1; i <= colCount; i++) { fg.SetData(rg.r1, rg.c1 + (i * stepValue), val + (i * stepValue)); } } } else if (actualDataType == typeof(DateTime)) { // This function follows behavior similar to Excel // When the DataTime value is Autofilled using Fill handle // feature, only the last part of the DateTime value is increased. DateTime val; DateTime.TryParse(data.ToString(), out val); string mainSubStr = data.ToString().Substring(0, data.ToString().LastIndexOf('/') + 1); string lastSubStr = data.ToString().Substring(data.ToString().LastIndexOf('/') + 1); int endVal = int.Parse(lastSubStr); if (rowCount > colCount) { for (int i = 1; i <= rowCount; i++) { int finalVal = endVal + (i * stepValue); string endStr = finalVal.ToString(); if (finalVal.ToString().Length < lastSubStr.Length) { endStr = "0" + endStr; } fg.SetData(rg.r1 + (i * stepValue), rg.c1, mainSubStr + endStr); } } else { for (int i = 1; i <= colCount; i++) { int finalVal = endVal + (i * stepValue); string endStr = finalVal.ToString(); if (finalVal.ToString().Length < lastSubStr.Length) { endStr = "0" + endStr; } fg.SetData(rg.r1, rg.c1 + (i * stepValue), mainSubStr + endStr); } } } else if (actualDataType == typeof(string)) { rg.Data = startCell.Data; } } } else { C1.Win.C1FlexGrid.CellRange rg = fg.Selection; rg.Data = startCell.Data; } } }